推荐学习书目
› 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
0D
V2EX  ›  Python

爬虫 Connection aborted 请教

  •  
  •   livc ·
    livc · Jul 29, 2017 · 11162 views
    This topic created in 3418 days ago, the information mentioned may be changed or developed.

    最近写了一个简单的模拟发送请求的脚本,大约可用一周后就会报出如下错误,当重新抓一下 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 replies  •  2017-07-30 10:39:29 +08:00
    bazingaterry
    bazingaterry
    Jul 29, 2017 via iPhone
    1
    try ... except ... 然后重新获取 Cookies ?
    livc
    livc
    OP
    Jul 29, 2017
    2
    @bazingaterry #1 cookies 是手动在 web 页面抓的。。
    Keyes
    Keyes
    Jul 29, 2017 via iPad
    3
    哈哈哈哈终身代号 9527
    bazingaterry
    bazingaterry
    Jul 29, 2017 via iPhone
    4
    @livc 如果可以的话改成用代码获取呗……
    xujialiang
    xujialiang
    Jul 29, 2017 via iPhone
    5
    登录过期,就模拟登录呗
    ivechan
    ivechan
    Jul 29, 2017
    6
    大约一周, 那就是 Cookie 生命周期只有一周?? 重新登录不就行了.
    livc
    livc
    OP
    Jul 29, 2017
    7
    @ivechan #6 重新登录比较麻烦
    sunbeams001
    sunbeams001
    Jul 30, 2017
    8
    服务端过期基本没办法
    换个思路,手机端一般会有类似延长 token 的机制
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   965 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 18:52 · PVG 02:52 · LAX 10:52 · JFK 13:52
    ♥ Do have faith in what you're doing.