-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyzer.py
140 lines (128 loc) · 4.65 KB
/
analyzer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import ActionChains
import time
# Function to navigate to a group by name
def goToGroup(driver, name):
inp_xpath_search = '//*[@id="side"]/div[1]/div/div/div[2]/div/div[1]/p'
input_box_search = WebDriverWait(driver, 50).until(
lambda driver: driver.find_element(By.XPATH, inp_xpath_search)
)
input_box_search.click()
time.sleep(1)
input_box_search.send_keys(Keys.COMMAND + "a")
input_box_search.send_keys(Keys.DELETE)
time.sleep(1)
input_box_search = WebDriverWait(driver, 50).until(
lambda driver: driver.find_element(By.XPATH, inp_xpath_search)
)
input_box_search.send_keys(name)
time.sleep(1)
input_box_search.send_keys(Keys.ENTER)
# Function to retrieve names from a group
def getFromGroup(driver):
driver.find_element(By.XPATH, '//*[@id="main"]/header').click()
time.sleep(1)
allbar = driver.find_element(
By.CLASS_NAME,
"_1UABU.q1n4p668.ln8gz9je.ddw6s8x9.p357zi0d.gndfcl4n.pm5hny62.os03hap6",
)
ar = []
ext = False
try:
allbar.find_element(By.CLASS_NAME, "ggj6brxn.ljrqcn24.jq3rn4u7")
ext = True
except:
ext = False
if ext:
allbar.click()
time.sleep(2)
for i in range(10):
names = driver.find_element(
By.XPATH, '//*[@id="app"]/div/span[2]/div/span/div/div/div/div/div/div'
).find_elements(
By.CLASS_NAME,
"ggj6brxn.gfz4du6o.r7fjleex.g0rxnol2.lhj4utae.le5p0ye3.l7jjieqr._11JPr",
)
for name in names:
ar.append(str(name.text))
driver.execute_script(
"arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;",
driver.find_element(
By.XPATH,
'//*[@id="app"]/div/span[2]/div/span/div/div/div/div/div/div/div[2]',
),
)
time.sleep(1)
ar = list(set(ar))
ActionChains(driver).send_keys(Keys.ESCAPE).perform()
else:
allbar.click()
time.sleep(1)
names = driver.find_element(
By.XPATH,
'//*[@id="app"]/div/div/div[6]/span/div/span/div/div/div/section/div[7]',
).find_elements(
By.CLASS_NAME,
"ggj6brxn.gfz4du6o.r7fjleex.g0rxnol2.lhj4utae.le5p0ye3.l7jjieqr._11JPr",
)
for name in names:
ar.append(str(name.text))
return ar
# Function to retrieve names from the community
def getFromCommunity(driver):
driver.find_element(By.XPATH, '//*[@id="main"]/header/div[2]').click()
time.sleep(1)
driver.find_element(
By.XPATH,
'//*[@id="app"]/div/div/div[6]/span/div/span/span/div/div/section/div[2]/div/div/button[1]',
).click()
time.sleep(1)
driver.find_element(
By.CLASS_NAME,
"_1UABU.q1n4p668.ln8gz9je.ddw6s8x9.p357zi0d.gndfcl4n.pm5hny62.os03hap6",
).click()
time.sleep(2)
ar = []
for i in range(10):
names = driver.find_element(
By.XPATH, '//*[@id="app"]/div/span[2]/div/span/div/div/div/div/div/div/div'
).find_elements(
By.CLASS_NAME,
"ggj6brxn.gfz4du6o.r7fjleex.g0rxnol2.lhj4utae.le5p0ye3.l7jjieqr._11JPr",
)
for name in names:
ar.append(str(name.text))
driver.execute_script(
"arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;",
driver.find_element(
By.XPATH,
'//*[@id="app"]/div/span[2]/div/span/div/div/div/div/div/div/div/div[2]',
),
)
time.sleep(1)
ar = list(set(ar))
ActionChains(driver).send_keys(Keys.ESCAPE).perform()
return ar
# Function to get names from a group
def getNamesFromGroup(driver, name):
goToGroup(driver, name)
return getFromGroup(driver)
# Function to get names from a community
def getNamesFromCommunity(driver, name):
goToGroup(driver, name)
return getFromCommunity(driver)
# Function to get names from a group and write them to a file
def getAndWriteToFile(driver, fname):
names = getNamesFromGroup(driver, fname)
with open(fname + ".txt", "w") as file:
for item in names:
file.write(item + "\n")
print("Finished " + fname + "!")
# Function to get names from multiple groups and write them to files
def getAndWriteToFiles(arr):
for i in arr:
getAndWriteToFile(i)