-
Notifications
You must be signed in to change notification settings - Fork 1
/
Harv.py
234 lines (209 loc) · 8.21 KB
/
Harv.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
from bs4 import BeautifulSoup
import urllib3
import urllib
import re
import sys
reload(sys)
import os.path
sys.setdefaultencoding('utf8')
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
parser = argparse.ArgumentParser(add_help=True, description='People Yandex Parser')
parser.add_argument('-w', '--work', required=True, help='Place of work')
parser.add_argument('-l', '--last', required=False, type=int, help='Last page to parse, default is 10')
parser.add_argument('-f', '--first', required=False, type=int, help='First page to parse, default is 0')
parser.add_argument('-e', '--email', required=False, help='End of Emails')
parser.add_argument('-s', '--save_to_file', default='WTFIMDOINGNOWLONGSTRING', type=str, help='Save to file(default place of work))', action="store",nargs='?')
parser.add_argument('-t', '--type', required=False, type=int,
help='Type of generation(1=N.Surname,2=Surname.N,3=Surname,4=Surname.N.P,5=SurnameN,6=NSurname,7=NameS,8=SName,9=Arabs(dont delete -))')
args = parser.parse_args()
if args.type is None: args.type = 1
if args.email is None: args.email = ""
if args.last is None: args.last = 10
if args.first is None: args.first = 0
if args.save_to_file is None: args.save_to_file = args.work
emails = set()
page = args.first
last = args.last
work=urllib.quote_plus(args.work)
type = args.type
url = "https://yandex.ru/people?ps_job=" + work + "&ps_network=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17&p="
http = urllib3.PoolManager()
def GetURL(url, page):
http = urllib3.PoolManager()
url = url + str(page)
#print url
print ("-------" + "scanning " + str(page) + " page--------")
r = http.request('GET', url)
print ("----------" + "status:" + str(r.status) + "--------")
#print r.data
return r.data
def transliterate(string):
capital_letters = {u'А': u'A',
u'Б': u'B',
u'В': u'V',
u'Г': u'G',
u'Д': u'D',
u'Е': u'E',
u'Ё': u'E',
u'Ж': u'Zh',
u'З': u'Z',
u'И': u'I',
u'Й': u'Y',
u'К': u'K',
u'Л': u'L',
u'М': u'M',
u'Н': u'N',
u'О': u'O',
u'П': u'P',
u'Р': u'R',
u'С': u'S',
u'Т': u'T',
u'У': u'U',
u'Ф': u'F',
u'Х': u'H',
u'Ц': u'Ts',
u'Ч': u'Ch',
u'Ш': u'Sh',
u'Щ': u'Sch',
u'Ъ': u'',
u'Ы': u'Y',
u'Ь': u'',
u'Э': u'E',
u'Ю': u'Yu',
u'Я': u'Ya', }
lower_case_letters = {u'а': u'a',
u'б': u'b',
u'в': u'v',
u'г': u'g',
u'д': u'd',
u'е': u'e',
u'ё': u'e',
u'ж': u'zh',
u'з': u'z',
u'и': u'i',
u'й': u'y',
u'к': u'k',
u'л': u'l',
u'м': u'm',
u'н': u'n',
u'о': u'o',
u'п': u'p',
u'р': u'r',
u'с': u's',
u'т': u't',
u'у': u'u',
u'ф': u'f',
u'х': u'h',
u'ц': u'ts',
u'ч': u'ch',
u'ш': u'sh',
u'щ': u'sch',
u'ъ': u'',
u'ы': u'y',
u'ь': u'',
u'э': u'e',
u'ю': u'yu',
u'я': u'ya', }
translit_string = ""
for index, char in enumerate(string):
if char in lower_case_letters.keys():
char = lower_case_letters[char]
elif char in capital_letters.keys():
char = capital_letters[char]
if len(string) > index + 1:
if string[index + 1] not in lower_case_letters.keys():
char = char.upper()
else:
char = char.upper()
translit_string += char
return translit_string
def surname(string):
return (filter(lambda x: x.isalpha(), string[string.rfind(" ") + 1:]))
def name(string):
return (string[:string.find(" ")])
def dog(end_of_email):
if end_of_email == "":
return ("")
else:
return ("@" + end_of_email)
def email(string, type):
if type == 1:
return (name(string)[0] + "." + surname(string) + dog(args.email))
if type == 2:
return (surname(string) + "." + name(string)[0] + dog(args.email))
if type == 3:
return (surname(string) + dog(args.email))
if type == 4:
return (surname(string) + "." + name(string)[0])
if type == 5:
return (surname(string) + name(string)[0]+ dog(args.email))
if type == 6:
return (name(string)[0]+ surname(string) + dog(args.email))
if type == 7:
return (name(string)+surname(string)[0] + dog(args.email))
if type == 8:
return (surname(string)[0] + name(string)+ dog(args.email))
if type == 9:
return (name(string)[0] + "."+ string[string.find(" ")+1:].strip().replace(" ","-")+ dog(args.email))
def Save_file(emails):
if os.path.exists(str(args.save_to_file).replace(" ", "_")+'.txt')==True:
print ("W0W W0W W0W Pogodi pogodi pogodi(untranslatable wordplay)")
print ("This file already exists")
print ("What would you like to do?")
print ("Delete or append to the end ?(d/a)")
name=raw_input()
if name=="d" or name=="D":
print("Prepare to destroy with greek bloods")
print("The file is overwritten")
f = open(str(args.save_to_file).replace(" ", "_")+'.txt', 'w')
for element in emails:
f.write(element + '\n')
else:
if name=="a" or name=="A":
print ("Ok,Append to the end of Death Star")
f = open(str(args.save_to_file).replace(" ", "_") + '.txt', 'a')
for element in emails:
f.write(element + '\n')
else:
print ("I dont understand-sorry")
else:
#print (False)
print("File doesnt exists")
print("Prepare to file creation")
f = open(str(args.save_to_file).replace(" ", "_")+'.txt', 'w')
print("File created")
for element in emails:
f.write(element + '\n')
def main():
list_elements = set()
for i in range(page, last + 1):
file = GetURL(url, i)
soup = BeautifulSoup(file, 'html.parser') # загружаем html в суп
divs = soup.findAll(name='li', attrs={'class': 'serp-item'})
if not divs: break # ищем дивы
for element in divs:
name=element.find(name='div', attrs={'class': 'organic__url-text'})
name = name.get_text()
name=name.decode('utf-8')
name=name[:name.rfind("–")]
name=transliterate(name).strip()
list_elements.add(name)
print ("")
print ("I find " + str(len(list_elements)) +" people")
print ("Thank You for choosing our company")
print ("")
for element in list_elements:
if type != 4:
emails.add(email(element, type))
else:
for i in range(65, 91):
emails.add(email(element, 4) + "." + chr(i) + dog(args.email))
for element in emails:
print (element)
if args.save_to_file!="WTFIMDOINGNOWLONGSTRING":
Save_file(emails)
if __name__ == "__main__":
main()