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
dedewei
V2EX  ›  Python

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

  •  
  •   dedewei · 2015-04-03 13:50:48 +08:00 · 4608 次点击
    这是一个创建于 3314 天前的主题,其中的信息可能已经有所发展或是发生改变。
    错误信息:
    requests.exceptions.Connecti onError: ('Connection aborted.', error(104, 'Connection reset by peer'))

    加了headers也不行

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

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