-
Notifications
You must be signed in to change notification settings - Fork 51
/
kq36.1.py
347 lines (293 loc) · 10.9 KB
/
kq36.1.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
from bs4 import BeautifulSoup
import requests
import xlsxwriter
import re
def get_link():
name='全国公立医院'
f=open(name+'link1.txt','a+',encoding='utf-8')
f1=open(name+'error1.txt','a+',encoding='utf-8')
for i in open(name+'error.txt','r',encoding='utf-8'):
print('第'+str(i)+'页')
url='https://3g.kq36.cn/2000/?pageindex='+str(i)
req=requests.get(url)
bsObj=BeautifulSoup(req.text,'html.parser')
ul=bsObj.find('table',{'id':'thelist'})
try:
lilist=ul.find_all('tr')
except:
f1.write(str(i))
continue
print(len(lilist))
for tr in lilist:
a=tr.find('a')
href=a.attrs['href']
if 'javascript' in href:
# print(a.attrs['onclick'])
href=re.search(r"else{\$\(this\).attr\(\'href\',\'(.+?)\'\)}",a.attrs['onclick']).group(1)
name=tr.find('li',class_='title').get_text().strip()
address=tr.find('li',class_='titlec').get_text().strip()
# print(li)
row=[href,name,address]
f.write(str(row)+'\n')
if len(lilist)<10:
break
f.close()
f1.close()
# get_link()
def get_proxies_abuyun():
proxyHost = "http-dyn.abuyun.com"
proxyPort = "9020"
# 代理隧道验证信息
proxyUser = 'HR3LY43V4QOU249D'
proxyPass = 'F89DAEA7A6C85E23'
proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
"host": proxyHost,
"port": proxyPort,
"user": proxyUser,
"pass": proxyPass,
}
proxies = {
"http": proxyMeta,
"https": proxyMeta,
}
return proxies
def get_detail():
name='全国公立医院'
f1=open(name+'detail.txt','a+',encoding='utf-8')
f2=open(name+'link_error3.txt','a+',encoding='utf-8')
# root='http://jobs.kq88.com'
# 'https://www.kq159.com/yayale508/?comid=3&comname=%E5%85%A8%E5%9B%BD%E7%89%99%E7%A7%91&tmp=1548062662000'
# 'https://3g.kq36.com/jobs/2187733'
i=0
for line in open(name+'link_error2.txt','r',encoding='utf-8'):
print(i)
line=eval(line)
url=line[0]
if 'www.kq159.com' in url:
# om/yy828083/?comid=3&com
id=re.search(r'ww.kq159.com/(.+?)/\?comid=',url).group(1)
print(id)
url='https://www.kq159.com/'+id+'/contact.html?'
print(url)
for m in range(5):
try:
if '3g.kq36.com' in url:
req=requests.get(url,timeout=15,proxies=get_proxies_abuyun())
req.encoding='gb2312'
break
else:
req=requests.get(url,timeout=15)
req.encoding='utf-8'
break
except:
pass
if m==4:
f2.write(str(line)+'\n')
continue
bsObj=BeautifulSoup(req.text,'lxml')
if '3g.kq36.com' in url:
# row=g_kq36(url,f2)
# print(bsObj)
# break
if '3g.kq36.com/jobs' in url:
div=bsObj.find('div',class_='r4')
line.append(str(div))
else:
div=bsObj.find('div',class_='r1')
line.append(str(div))
elif 'www.kq159.com' in url:
div=bsObj.find('ul',class_='c_infos')
line.append(str(div))
# print(div)
# break
else:
f2.write(str(line)+'\n')
continue
# print(line)
f1.write(str(line)+'\n')
# break
i=i+1
# if i==10:
# break
f1.close()
f2.close()
# get_detail()
def write_excel():
name='全国牙科'
workbook = xlsxwriter.Workbook(name+'.xlsx') #创建工作簿
sheet = workbook.add_worksheet()
r=0
for line in open('qgykdetail.txt','r',encoding='utf-8'):
line=eval(line)
# print(line)
url=line[0]
wx=''
phone=''
t_phone=''
mail=''
address=''
web_url=''
p_name=''
bsObj=BeautifulSoup(line[3],'lxml')
if '3g.kq36.com' in url:
if 'govzp' in url:
div=bsObj.find_all('div')
for d in div:
if '联系' in d.get_text():
p_name=d.get_text().replace('联系','')
continue
if '电话' in d.get_text():
alist=d.find_all('a')
for a in alist:
phone=phone+a.attrs['href']+'_'
continue
if '邮件' in d.get_text():
mail=d.get_text().replace('邮件','')
continue
if '地址' in d.get_text():
address=d.get_text().replace('地址','')
continue
if '官网' in d.get_text():
web_url=d.get_text().replace('官网','')
continue
else:
div=bsObj.find_all('ul')
for ul in div:
if '电话' in ul.get_text():
t_phone=ul.find('li',class_='c2').get_text()
continue
if '联系' in ul.get_text():
p_name=ul.find('li',class_='c2').get_text()
continue
if '手机' in ul.get_text():
try:
ali=ul.find('li',class_='c2').find_all('a')
for a in ali:
phone=phone+a.attrs['href']+'_'
# phone=ul.find('li',class_='c2').find('a').attrs['href']
except:
phone=ul.find('li',class_='c2').get_text()
continue
if '微信' in ul.get_text():
wx=ul.find('li',class_='c2').get_text()
continue
if '邮箱' in ul.get_text():
try:
mail=ul.find('li',class_='c2').find('a').attrs['href']
except:
mail=ul.find('li',class_='c2').get_text()
continue
if '地址' in ul.get_text():
address=ul.find('li',class_='c2').get_text()
continue
elif 'www.kq159.com' in url:
try:
p_name=bsObj.find('li',class_='c_p1').get_text()
except:
p_name=''
try:
ali=bsObj.find('li',class_='c_p2').find_all('a')
for a in ali:
hr=a.attrs['href']
if 'javasc' in hr:
hr=a.get_text()
phone=phone+hr+'_'
except:
phone=''
try:
mail=bsObj.find('li',class_='c_p4').get_text().split('?')[0]
except:
mail=''
try:
wx=bsObj.find('li',class_='c_p7').get_text()
except:
wx=''
try:
web_url=bsObj.find('li',class_='c_p8').get_text()
except:
web_url=''
try:
address=bsObj.find('li',class_='c_p5').get_text()
except:
address=''
else:
pass
if phone=='' and mail=='' and wx==''and t_phone=='':
continue
address=address.split('地图')[0]
if len(phone)>255:
phone=''
row=line[:2]+[p_name,t_phone,phone,mail,wx,web_url,address]
for i in range(len(row)):
# if len(row[i])>255:
# print(row)
# print(i)
# row[i]=''
sheet.write(r,i,row[i].replace('\r','').replace('\n','').replace('\t','').replace('\xa0','').strip())
r=r+1
# print(r)
# print(row)
# break
workbook.close()
write_excel()
# def get_detail():
# f1=open(name+'detail.txt','a+',encoding='utf-8')
# f2=open(name+'link_error.txt','a+',encoding='utf-8')
# # root='http://jobs.kq88.com'
# # 'https://www.kq159.com/yayale508/?comid=3&comname=%E5%85%A8%E5%9B%BD%E7%89%99%E7%A7%91&tmp=1548062662000'
# # 'https://3g.kq36.com/jobs/2187733'
# i=0
# for line in open(name+'link.txt','r',encoding='utf-8'):
# print(i)
# i=i+1
# line=eval(line)
# url=line[0]
# if 'www.kq159.com' in url:
# # om/yy828083/?comid=3&com
# id=re.search(r'ww.kq159.com/(.+?)/\?comid=',url).group(1)
# print(id)
# url='https://www.kq159.com/'+id+'/contact.html?'
# print(url)
# try:
# if '3g.kq36.com' in url:
# req=requests.get(url,timeout=15,proxies=get_proxies_abuyun())
# req.encoding='gb2312'
# else:
# req=requests.get(url,timeout=15)
# req.encoding='utf-8'
# except:
# f2.write(str(line)+'\n')
# continue
# bsObj=BeautifulSoup(req.text,'lxml')
# ul=bsObj.find('ul',class_='c_infos')
# try:
# mainUrl=ul.find('li',class_='c_p1').get_text()
# phone=ul.find('li',class_='c_p2').find('a').attrs['href']
# address=ul.find('li',class_='c_p5').get_text()
# except:
# f2.write(str(line)+'\n')
# continue
# # print(line)
# line=line+[mainUrl,phone,address]
# f1.write(str(line)+'\n')
# # break
# # if i==10:
# # break
# f1.close()
# f2.close()
# # get_detail()
# def write_excel():
# workbook = xlsxwriter.Workbook(name+'.xlsx') #创建工作簿
# sheet = workbook.add_worksheet()
# r=0
# for line in open(name+'detail.txt','r',encoding='utf-8'):
# row=eval(line)
# # print(line)
# for i in range(len(row)):
# sheet.write(r,i,row[i].replace('\r','').replace('\n','').replace('\t','').replace('\xa0','').strip())
# r=r+1
# # print(r)
# # print(row)
# # break
# workbook.close()
# write_excel()