-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_concat.py
389 lines (338 loc) · 23.4 KB
/
test_concat.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#coding: utf-8
import os,sys
import re
import time
from datetime import datetime
from lxml import etree
import requests
import json
from scrapy.selector import Selector
from PIL import Image,ImageChops
import cPickle
import test_getdata
from selenium import webdriver
from pyvirtualdisplay import Display
import socket
socket.setdefaulttimeout(20)
reload(sys)
sys.setdefaultencoding('utf8')
ss ="""<div class="gt_cut_fullbg gt_show"><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -157px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -145px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -265px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -277px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -181px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -169px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -241px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -253px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -109px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -97px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -289px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -301px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -85px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -73px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -25px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -37px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -13px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -1px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -121px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -133px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -61px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -49px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -217px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -229px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -205px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -193px -58px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -145px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -157px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -277px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -265px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -169px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -181px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -253px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -241px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -97px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -109px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -301px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -289px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -73px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -85px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -37px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -25px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -1px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -13px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -133px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -121px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -49px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -61px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -229px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -217px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -193px 0px;"></div><div class="gt_cut_fullbg_slice" style="background-image: url("http://static.geetest.com/pictures/gt/895656306/895656306.webp"); background-position: -205px 0px;"></div></div>"""
image_save_path = '/home/moma/captcha_images/'
static_servers = "http://static.geetest.com/"
if not os.path.exists(image_save_path):
os.system('mkdir %s'%image_save_path)
def download_img(url,name):
res = requests.get(url)
image_path = image_save_path+name
try:
with open(image_path,'wb') as f:
f.write(res.content)
print "image_save success!"
return Image.open(image_path)
except Exception as e:
print e
print "--------------download image: %s failed,url is: %s--------------"%(name,url)
def get_pos(ss):
res = re.findall(r'-\w+?px\s-*\w+?px;\"',ss)
# print res
result = []
for item in res:
result.append(re.findall(r'\d+',item))
return result
def recover(img,pos):
size = img.size
#先生成一块一样大小的空图片
im = Image.new('RGBA',size)
cols = len(pos)/2
# print "cols:",cols
for count,item in enumerate(pos):
# print count
col = round(count/cols)
# print count,col
posx = int(item[0])
posy = int(item[1])
box = (posx,posy,posx+10,posy+58)
region = img.crop(box)
# origin_box = ((count%cols)*12,int(col)*58,(count%cols)*12+12,(int(col)*58)+58)
origin_box = ((count%cols)*10,int(col)*58)
# print origin_box
im.paste(region,origin_box)
return im
def get_dist(image1_url,image2_url):
# location_list
################################
image1 = download_img(image1_url,'fullbg.jpg')
image2 = download_img(image2_url,'bg.jpg')
pos = get_pos(ss)
im1 = recover(image1,pos)
# print "im1.size--------------------------->",im1.size
# im1.show()
im2 = recover(image2,pos)
# im2.show()
################################
im = ImageChops.difference(im1,im2)
width,height = im.size
count = 0
for i in range(width):
color_count = 0
for j in range(height):
count += 1
# print "count,width,height =",count,i,j
# print im.getpixel((i,j))
if color_count >30:
return im,i
if sum(im.getpixel((i,j))) > 120:
color_count += 1
elif sum(im.getpixel((i,j))) <=120:
color_count = 0
return im,-1
def capture(url):
file_path = save_dir + os.sep + "%s.png"%str(url)
if os.path.exists(file_path):
print '== == == %s exist' %(url)
return
print url
display = Display(visible=0, size=(1920, 1080))
display.start()
try:
browser = webdriver.Chrome()
except Exception, e:
print 'e0'
print e
return
wait_time = 1
try:
time.sleep(2)
browser.get("http://"+url)
except socket.timeout:
print 'exit, socket, timeout'
except Exception, e:
print 'e1', e
try:
browser.save_screenshot(file_path)
except Exception, e:
print 'e2', e
else:
print "+++ +++ +++ %s" % (file_path)
browser.quit()
display.stop()
headers = {'Accept':'*/*',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'en-US,en;q=0.8',
'Connection':'keep-alive',
'Cookie':'GeeTestUser=a3e643b51de0e88532b5f0e3e7e0e3d4; GeeTestAjaxUser=da53de5a02bd8f51ee602446622f9244; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2215df9c149461be-00ab768a82dd6d-3977065e-2073600-15df9c14948f1%22%2C%22props%22%3A%7B%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%7D%7D; Hm_lvt_25b04a5e7a64668b9b88e2711fb5f0c4=1503133782; Hm_lpvt_25b04a5e7a64668b9b88e2711fb5f0c4=1503134226',
'Host':'api.geetest.com',
'Referer':'http://www.gsxt.gov.cn/corp-query-search-1.html',
'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36'}
headers1 = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0'}
headers2 = {'cache-control': 'no-cache, no-store, must-revalidate','connection': 'keep-alive','content-length': 729,'content-type': 'text/javascript;charset=UTF-8'}
def fake_ax():
#时间戳
url1 = 'http://www.gsxt.gov.cn/SearchItemCaptcha?v=[__time__]'
url2 = 'http://api.geetest.com/get.php?gt=[__gt__]&challenge=[__challenge__]&product=popup&offline=false&protocol=&path=/static/js/geetest.5.10.10.js&type=slide&callback=geetest_[__callback__]'
url3 = 'http://api.geetest.com/ajax.php?gt=1d2c042096e050f07cb35ff3df5afd92&challenge=3a1502d5b2886923bc933d1ada15959ecj&userresponse=60606606060b3&passtime=1694&imgload=72&a=B%2C..1%2F%2F.00%2F-%2F.%2F--(!!Essty!)!)z!)!)!)(!*!)((((t(((z(ttu(!!(%24)%2F%24)%3A9%3A%3A9%3A9%3A%3A9%3F99%3A%40B39%3F%3A999%24%2FOD%2447&callback=geetest_1503304071186'
t = time.time()
t = int(round(1000*t))
t = str(t)
url1 = url1.replace('[__time__]',t)
print "url1-->",url1
res = requests.get(url1,headers = headers1)
json_res = json.loads(res.content)
challenge = json_res['challenge']
gt = json_res['gt']
print "1111chanllenge:",challenge
print "1111gt:",gt
url2 = url2.replace('[__gt__]',gt)
url2 = url2.replace('[__challenge__]',challenge)
t = time.time()
###callback参数最后为毫秒级的时间戳
callback = int(round(1000*t))
callback = str(callback)
print "callback----->",callback
url2 = url2.replace('[__callback__]',callback)
print url2
res2 = requests.get(url2)
print res2
print "res2 ------>\n",res2.content
# tmp = res2.content
# my_challenge = re.findall(r'\"challenge\"\:\s\"[\w\W]+?\"',tmp)
# my_challenge = my_challenge[0].split(' ')[-1]
# print "my_challenge----->",my_challenge
dict2 = re.findall(r'\{[\s\S]+\}',res2.content)
res3 = json.loads(dict2[0])
print "!!!!!!res3!!!!!!!!!\n",res3
fullbg_url = static_servers + res3['fullbg']
print "fullbg_url----->",fullbg_url
bg_url = static_servers + res3['bg']
# download_img(fullbg_url,'fullbg.jpg')
# download_img(bg_url,'bg.jpg')
# pos = get_pos(ss)
# img1_path = image_save_path+'fullbg.jpg'
# img2_path = image_save_path+'bg.jpg'
# img1 = Image.open(img1_path)
# img2 = Image.open(img2_path)
###下面返回的dist就是要滑动的距离
im,dist = get_dist(fullbg_url,bg_url)
print "dist---->",dist
# im.show()
challenge = res3['challenge']
# print "12345",my_challenge
# print type(my_challenge)
return gt,challenge,dist-6
# challenge,validate = get_validate(gt,challenge)
# print "validate---->",validate
# print "challenge--->",challenge
# url3 = url3.replace('[__gt__]',gt)
# url3 = url3.replace('[__challenge]',challenge)
# t = time.time()
# ###callback参数最后为毫秒级的时间戳
# callback = int(round(1000*t))
# callback = str(callback)
# url3 = url3.replace('[__callback__]',callback)
# print url3
# res3 = requests.get(url1,headers = headers)
# json_res3 = json.loads(res3.content)
# print 'res3:------------',json_res3
def get_validate(gt,challenge,dist):
try:
# 获得bg和fullbg
# challenge,bg,fullbg=get_bg_fullbg(gt,challenge)
# print 'challenge:',challenge
# print 'bg:',bg
# print 'fullbg:',fullbg
# # 缺口距离 供编写鼠标轨迹使用 距离边框6
# dist=get_dist(bg,fullbg)-6
# print 'dist:',dist
# 根据dist挑选一个路径
# track来自文件 teg=1 否则 0
track,tag=test_getdata.choice_track_list(dist) # 来自训练路径 tag=1
print "-------track---------%s\n"%track
print "--------tag----------\n"
# print "--------tag----------%s\n"%tag
# 规范化轨迹数据 [[x,y,t],...]
track_list=test_getdata.format_track(track) # 路径列表
print "track_list----------------\n"
# print "track_list---------------->\n",track_list
# 若tag==0,即轨迹数据不在已收集的轨迹文件中(来自候选轨迹列表),
# 则截取路径(从中截取需要的长度)
if tag!=1:
new_track_list=test_getdata.create_track(track_list,dist)
# print "if---------new_track_list---------%s\n"%new_track_list
print "if---------new_track_list---------\n"
else:
# tag==1 轨迹数据来自文件 直接赋值
new_track_list=track_list
print "else---------new_track_list---------\n"
# print "else---------new_track_list---------%s\n"%new_track_list
print "new_track_list------------->\n",new_track_list
# 根据challenge和 new_track_list
# 计算 userresponse 和 a 参数
userresponse,a=test_getdata.get_userresponse_a(challenge,new_track_list)
print 'userresponse:------------------>',userresponse
print 'a:----------------------------->',a
url='http://api.geetest.com/ajax.php'
# passtime parse_3所需的参数
passtime=new_track_list[-1][-1]
print 'passtime:',passtime
# 防止太频繁 休眠时间可改短
time.sleep(2)
# 获得 validate
validate=test_getdata.parse_3(url,gt,challenge,userresponse,passtime,a)
time.sleep(2)
# if len(validate)>0:
# print challenge
# print validate
return challenge,validate
except Exception,e:
print "error happens------------------------>"
print e
return '','error validate'
def get_uri(page):
links=[]
alist=page.xpath(u'//a[@class="search_list_item db"]')
web_site='http://www.gsxt.gov.cn'
for item in alist:
# print item.attrib['href']
links.append(web_site+item.attrib['href'])
return links
file_save_path = '/home/moma/Documents/codes/capture_project/results/'
def write_result(link,headers):
res = requests.get(link,headers = headers)
sel = Selector(text = res.content)
title = sel.xpath('//div[@class="overview"]/dl/dd/text()')[1].extract()
# title = sel.xpath('//div[@class="details clearfix"]//div[@class="classify"]/text()').extract()[0]
content = sel.xpath('//div[@class = "details clearfix"]//text()').extract()
clean_content = re.sub(r'[\r\n\t]*','',''.join(content))
# clean_content = re.sub(r'\s+',' ',clean_content)
file_path = file_save_path + title +'.txt'
with open(file_path,'wb') as f:
f.write(clean_content)
if "__main__" == __name__:
# searchword='百度'
pageNo=1
data_href='http://www.gsxt.gov.cn/corp-query-search-%s.html' %(pageNo)
headers = {
"Origin": "http://www.gsxt.gov.cn",
"Proxy-Connection": "keep-alive",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36",
"Host": "www.gsxt.gov.cn",
"Referer": "http://www.gsxt.gov.cn/index.html",
"Cache-Control": "max-age=0"
}
# searchwords = ['百度','新浪','网易','阿里巴巴','腾讯','滴滴','饿了么']
# headers = {
# "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
# "Accept-Encoding": "gzip, deflate",
# "Accept-Language":"en-US,en;q=0.8",
# "Cache-Control":"max-age=0",
# "Connection":"keep-alive",
# "Content-Length":"218",
# "Content-Type":"application/x-www-form-urlencoded",
# "Cookie":"__jsluid=ab32016d61fdac95c25741901b64936b; UM_distinctid=15de9b8a585254-0c13ae767d293c-1c2f170b-1fa400-15de9b8a5881e7; Hm_lvt_d7682ab43891c68a00de46e9ce5b76aa=1503134021; Hm_lpvt_d7682ab43891c68a00de46e9ce5b76aa=1503300394; CNZZDATA1261033118=1468702795-1502861478-null%7C1503466331; JSESSIONID=DAE14DBF4D37999BA31881B790565849-n1:-1; Hm_lvt_cdb4bc83287f8c1282df45ed61c4eac9=1502867416,1503133180,1503133499,1503135143; Hm_lpvt_cdb4bc83287f8c1282df45ed61c4eac9=1503466488; tlb_cookie=42query_8080",
# "Host":"www.gsxt.gov.cn",
# "Origin":"http://www.gsxt.gov.cn",
# "Referer":"http://www.gsxt.gov.cn/corp-query-homepage.html",
# "Upgrade-Insecure-Requests":"1",
# "User-Agent":"Baiduspider+(+http://www.baidu.com/search/spider.htm)"
# }
# "User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36"
#####要搜索的关键词
searchwords = ['百度','网易']
for searchword in searchwords:
gt,challenge,dist = fake_ax()
print gt
print challenge
print dist
# print (get_pos(ss))
challenge, validate = get_validate(gt,challenge,dist)
print "\n######################validate########################"
print "validate---->",validate
data = {
"searchword": searchword,
"geetest_challenge": challenge,
"token": "41111854",
"tab": "",
"geetest_seccode": validate+"|jordan",
"geetest_validate": validate,
'page':str(pageNo)
}
print data
# 谨慎(请求必须加上headers) 稍不注意 就被短暂封ip
if validate!=None:
res=requests.post(data_href,headers=headers,data=data).content
# print "\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$res$$$$$$$$$$$$$$$$$$$$$$\n",res
page=etree.HTML(res)
links=test_getdata.get_uri(page)
print '查询结果如下:\n\n\n\n\n'
result_path = searchword+'.txt'
print "result_path---------->",result_path
# result_path = '/home/moma/Documents/codes/capture_project/results/'+searchword+'.txt'
# with open(result_path,'wb') as f:
for link in links:
print link
# write_result(link,headers)
# capture(link)
# f.write(link+'\n')
# content = requests.get(link,headers=headers).content
# print content.xpath()