V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
livc
V2EX  ›  Python

爬虫 Connection aborted 请教

  •  
  •   livc ·
    livc · 2017-07-29 00:53:00 +08:00 · 10359 次点击
    这是一个创建于 2469 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近写了一个简单的模拟发送请求的脚本,大约可用一周后就会报出如下错误,当重新抓一下 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',))
    
    8 条回复    2017-07-30 10:39:29 +08:00
    bazingaterry
        1
    bazingaterry  
       2017-07-29 00:58:52 +08:00 via iPhone
    try ... except ... 然后重新获取 Cookies ?
    livc
        2
    livc  
    OP
       2017-07-29 01:00:22 +08:00
    @bazingaterry #1 cookies 是手动在 web 页面抓的。。
    Keyes
        3
    Keyes  
       2017-07-29 01:26:03 +08:00 via iPad
    哈哈哈哈终身代号 9527
    bazingaterry
        4
    bazingaterry  
       2017-07-29 02:06:20 +08:00 via iPhone
    @livc 如果可以的话改成用代码获取呗……
    xujialiang
        5
    xujialiang  
       2017-07-29 11:19:57 +08:00 via iPhone
    登录过期,就模拟登录呗
    ivechan
        6
    ivechan  
       2017-07-29 17:03:09 +08:00
    大约一周, 那就是 Cookie 生命周期只有一周?? 重新登录不就行了.
    livc
        7
    livc  
    OP
       2017-07-29 17:05:46 +08:00
    @ivechan #6 重新登录比较麻烦
    sunbeams001
        8
    sunbeams001  
       2017-07-30 10:39:29 +08:00
    服务端过期基本没办法
    换个思路,手机端一般会有类似延长 token 的机制
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2318 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:34 · PVG 20:34 · LAX 05:34 · JFK 08:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.