-
Notifications
You must be signed in to change notification settings - Fork 51
/
kq36.py
234 lines (201 loc) · 6.96 KB
/
kq36.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
from bs4 import BeautifulSoup
import requests
import xlsxwriter
import re
#全国牙科
name='qgyk'
# 到1680
def get_link():
name='qgyk'
f=open(name+'link1.txt','a+',encoding='utf-8')
f1=open(name+'error2.txt','a+',encoding='utf-8')
n=0
for i in open(name+'error1.txt','r',encoding='utf-8'):
print('第'+str(i)+'页')
url='https://3g.kq36.cn/3/?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)+'\n')
continue
print(len(lilist))
for tr in lilist:
a=tr.find('a')
href=a.attrs['href']
if 'javascript' in href:
href=re.search(r"else{\$\(this\).attr\(\'href\',\'(.+?)\'\)}",a.attrs['onclick']).group(1)
else:
continue
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
n=n+1
if n==5:
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():
f1=open(name+'detail.txt','a+',encoding='utf-8')
f2=open(name+'link_error1.txt','w+',encoding='utf-8')
i=0
for line in open(name+'link1.txt','r',encoding='utf-8'):
print(i)
line=eval(line)
url=line[0]
if 'javascript' in url:
continue
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))
else:
f2.write(str(line)+'\n')
print('error')
continue
# print(line)
f1.write(str(line)+'\n')
i=i+1
f1.close()
f2.close()
# get_detail()
def write_excel():
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')
pass
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:
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:
phone=bsObj.find('li',class_='c_p2').get_text()
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
row=line[:3]+[p_name,t_phone,phone,mail,wx,web_url,address]
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()