-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.py
49 lines (39 loc) · 1.97 KB
/
script.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
import requests
import re
# Populate below list with URLs to be scraped
masterlist = ["https://clutch.co/agencies/new-york","https://clutch.co/uk/agencies/creative"]
headers = {'User-Agent': 'Mozilla\/5.0 \(Macintosh; Intel Mac OS X 10.14; rv:64.0\) Gecko\/20100101 Firefox\/64.0'}
def solver(lst,string):
strng = ""
for i in range(len(lst)):
strng += string.split('#')[lst[i]]
return strng
for ml in range(len(masterlist)):
initresponse = requests.get(masterlist[ml],headers=headers)
maxpages = re.findall(r"<li class=\"pager-current\">1 of (.*)</li>",initresponse.text)
print(maxpages[0])
for p in range(0,int(maxpages[0])+1):
response = requests.get(masterlist[ml]+'?page='+str(p),headers=headers)
toHit = re.findall(r"<a href=\"(https://clutch.co/profile/[\w\d-]*)\" target=\"_blank\">",response.text)
for brandUrl in toHit:
response1 = requests.get(brandUrl,headers=headers)
mails = re.findall(r"= '(.*[@]{1}.*)';",response1.text)
names = re.findall(r"(.*) </h1>",response1.text)
codes = re.findall(r"document.getElementById\(.*'\).innerHTML = (.*)",response1.text)
if len(mails) != 0:
for i in range(len(codes)):
codes[i] = re.sub("[^0-9]", "", codes[i])
codes[i] = [int(i) for i in str(codes[i])]
for j in range(len(mails)):
mails[j] = solver(codes[j],mails[j])
with open('lst.csv', 'a') as nm:
for k in range(len(names)):
nm.write(names[k]+","+mails[k])
nm.write("\n")
with open('progress.txt', 'a') as prog:
for mal in mails:
prog.write(brandUrl+" "+masterlist[ml]+'?page='+str(p))
prog.write("\n")
print(brandUrl+" "+masterlist[ml]+'?page='+str(p))
else:
print("No Email Found")