最近写了一个简单的模拟发送请求的脚本,大约可用一周后就会报出如下错误,当重新抓一下 cookie 时就又好用了,感觉貌似是反爬虫策略?应该如何应对?谢谢。
Traceback (most recent call last):
File "call.py", line 35, in <module>
r = requests.post('http://m.01zhuanche.com/touch/order/bookingCar', headers=header, data=book_data).json()
File "/Library/Python/2.7/site-packages/requests/api.py", line 110, in post
return request('post', url, data=data, json=json, **kwargs)
File "/Library/Python/2.7/site-packages/requests/api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "/Library/Python/2.7/site-packages/requests/adapters.py", line 473, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine('HTTP/1.1 9527 \r\n',))
1
bazingaterry 2017-07-29 00:58:52 +08:00 via iPhone
try ... except ... 然后重新获取 Cookies ?
|
2
livc OP @bazingaterry #1 cookies 是手动在 web 页面抓的。。
|
3
Keyes 2017-07-29 01:26:03 +08:00 via iPad
哈哈哈哈终身代号 9527
|
4
bazingaterry 2017-07-29 02:06:20 +08:00 via iPhone
@livc 如果可以的话改成用代码获取呗……
|
5
xujialiang 2017-07-29 11:19:57 +08:00 via iPhone
登录过期,就模拟登录呗
|
6
ivechan 2017-07-29 17:03:09 +08:00
大约一周, 那就是 Cookie 生命周期只有一周?? 重新登录不就行了.
|
8
sunbeams001 2017-07-30 10:39:29 +08:00
服务端过期基本没办法
换个思路,手机端一般会有类似延长 token 的机制 |