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

浏览器正常浏览,爬虫出错,都有哪些可能性?

  •  
  •   dedewei · Apr 3, 2015 · 5421 views
    This topic created in 4084 days ago, the information mentioned may be changed or developed.
    错误信息:
    requests.exceptions.Connecti onError: ('Connection aborted.', error(104, 'Connection reset by peer'))

    加了headers也不行

    这个问题经常出现,浏览器正常,但爬虫不行.
    1.想问问都有哪些可能性,遇到时有个线索可去google.
    2.模拟浏览器是不是只加headers就行? 是不是模拟成功的话就不会出错(浏览器能正常访问)?
    12 replies    2015-04-08 22:33:48 +08:00
    wdd2007
        1
    wdd2007  
       Apr 3, 2015
    你对比一下浏览器的请求和爬虫请求有哪些不一样的地方?

    比如 useragent、比如 cookie?
    willsplashing
        2
    willsplashing  
       Apr 3, 2015
    你确定python发出去的request和Chrome devtool里capture的request一模一样吗?
    willsplashing
        3
    willsplashing  
       Apr 3, 2015
    还有如果你爬虫一下子发很多request有些网站可能会有rate limit
    dedewei
        4
    dedewei  
    OP
       Apr 3, 2015
    @wdd2007
    @willsplashing 没有cookie,其他复制粘贴上去了
    dedewei
        5
    dedewei  
    OP
       Apr 3, 2015
    @willsplashing 爬了二十个页面就断了,然后时而行时而不行
    ETiV
        6
    ETiV  
       Apr 3, 2015 via iPhone
    firebug抓一次浏览器的请求,再用curl模拟提交(firebug有复制curl请求的功能),再一点点精简curl的参数
    cxl008
        7
    cxl008  
       Apr 3, 2015
    @dedewei 中间断掉的话考虑被对方服务器bang了 增加爬取时间间隔 或是用 分布式部署
    withrock
        8
    withrock  
       Apr 3, 2015
    可能和cookie有关,如果不需要登录就可以抓取的话,建议关闭cooke
    ps:我也写了个爬虫玩玩,互相学习。
    http://git.oschina.net/mktime/scrapy-douban-group
    libo26
        9
    libo26  
       Apr 3, 2015
    header与浏览器一致的话多半是频率限制了吧,增加时间间隔/换IP
    kkx
        10
    kkx  
       Apr 4, 2015
    用selenium 包治
    ioven
        11
    ioven  
       Apr 4, 2015
    burpsuite抓包,对比和浏览器的区别
    ming2281
        12
    ming2281  
       Apr 8, 2015
    了解一下HTTP协议,然后这些大都知道怎么避免了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5475 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 08:52 · PVG 16:52 · LAX 01:52 · JFK 04:52
    ♥ Do have faith in what you're doing.