· 7 years ago · Nov 04, 2018, 03:58 PM
1import time
2from selenium import webdriver
3from bs4 import BeautifulSoup as bs
4
5
6tab = []
7noms = []
8
9def Compteuresp(nomHumain):
10 compteuresp=0
11 text = nomHumain
12 for i in range(len(text)):
13 try :
14 if text[i]==' ':
15 compteuresp = compteuresp+1
16 except :
17 print ("Unicode Error")
18 continue
19 return compteuresp
20
21def Transformer(nomHumain):
22 del tab[:]
23 text = nomHumain
24 compteuresp = 0
25 compteur1 = 0
26 compteur = 0
27
28
29 for i in range(len(text)):
30 try :
31 if text[i]==' ':
32 compteuresp = compteuresp+1
33 tab.append(text[i])
34
35 except :
36 print ("Unicode Error")
37 continue
38
39 for i in range(len(tab)):
40 try :
41 if tab[i] == '(':
42 for j in range (i,len(tab)):
43 tab[j]=''
44 if text[i]==' ':
45 compteur1 = compteur1+1
46 if compteur1 ==2:
47 for j in range (i,len(tab)):
48 tab[j+1]=''
49
50 except :
51 continue
52
53 for i in range(len(tab)):
54 try :
55
56 if tab[i] == ' ':
57 if compteuresp == 2:
58 if compteur == 0:
59 tab[i]='.'
60 compteur = compteur +1;
61 elif compteur == 1 :
62 tab[i] = '@'
63 elif compteuresp ==1:
64 tab[i]='.'
65 tab.append('@')
66
67 if tab[i] == 'ç':
68 tab[i]='c'
69 if tab[i] == 'é':
70 tab[i]='e'
71 if tab[i] == 'ê':
72 tab[i]='e'
73 if tab[i] == 'ë':
74 tab[i]='e'
75 if tab[i] == 'Ã ':
76 tab[i]='a'
77 if tab[i] == 'ù':
78 tab[i]='u'
79 if tab[i] == 'è':
80 tab[i]='e'
81 if tab[i] == 'á':
82 tab[i]='a'
83 if tab[i] == 'Ã':
84 tab[i]='i'
85 if tab[i] == 'î':
86 tab[i]='i'
87 if tab[i] == 'ï':
88 tab[i]='i'
89 if tab[i] == 'ñ':
90 tab[i]='n'
91 if tab[i] == 'ú':
92 tab[i]='u'
93 if tab[i] == 'ù':
94 tab[i]='u'
95 if tab[i] == 'ó':
96 tab[i]='o'
97 if tab[i] == 'ò':
98 tab[i]='o'
99 if tab[i] == 'ô':
100 tab[i]='o'
101 if tab[i] == 'ö':
102 tab[i]='o'
103 if tab[i] == 'ä':
104 tab[i]='a'
105 if tab[i] == 'û':
106 tab[i]='u'
107 if tab[i] == 'ø':
108 tab[i]='o'
109 if tab[i] == '-':
110 tab[i]=''
111 if tab[i] == 'Č':
112 tab[i]='c'
113
114
115 except :
116 print ("Error")
117 continue
118
119
120 string = ""
121 for m in range (0,len(tab)):
122 string = string + tab[m]
123
124 print (string)
125 noms.append(string)
126
127
128
129
130browser = webdriver.Firefox()
131browser.get("https://www.facebook.com")
132
133browser.find_element_by_id("email").send_keys('j@gmail.com')
134browser.find_element_by_id("pass").send_keys("mdp")
135browser.find_element_by_id("loginbutton").click()
136
137
138
139
140browser.get("https://www.facebook.com/search/342030859226425/likers")
141time.sleep(8)
142
143lenOfPage = browser.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
144match=False
145while(match==False):
146 lastCount = lenOfPage
147 time.sleep(5)
148 lenOfPage = browser.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
149 if lastCount==lenOfPage:
150 match=True
151 print ("END OF PAGE")
152
153
154
155 # ATTENTION
156
157
158
159# La recherche des noms se fait APRES que la page ait été chargée, donc couper son internet pour lancer l'affichage des noms
160# Amélioration possible (?) : mettre l'affichage des noms en même temps que ça charge........ Nan après reflexion je crois que c'est pas possible lololol
161
162for p in range (3,40):
163 for n in range (1,7): # I (le 3 en dessous du I change en fonction du compte) ici la page ici le num
164 try:
165 path = '/html/body/div[1]/div[3]/div[1]/div/div[3]/div[2]/div/div/div[2]/div/div/div/div['+str(p)+']/div/div['+str(n)+']/div/div/div/div[2]/div/div[1]/div[2]/div/div/div/a/span'
166 nom = browser.find_element_by_xpath(path)
167 nomHumain = nom.text
168 if Compteuresp(nomHumain)<=2:
169 Transformer(nomHumain)
170 except :
171 continue
172
173
174f = open("nom.txt","a")
175for m in range (0,len(noms)):
176
177 try :
178
179 f.write (noms[m] + 'gmail.com' + "\n")
180 f.write (noms[m] + 'yahoo.fr' + "\n")
181 f.write (noms[m] + 'hotmail.com' + "\n")
182 f.write (noms[m] + 'outlook.com' + "\n")
183 f.write (noms[m] + 'outlook.fr' + "\n")
184
185 except :
186 continue
187f.close()
188time.sleep(1)
189
190# Le p (page) varie entre 3 et [infini] car les pages 1 et 2 ont des Xpath différents donc on les jette tant pis