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

Scrapy 爬取数据的时候,有什么 proxy 轮换的机制吗?

  •  1
     
  •   RangerWolf · 2015-05-07 11:16:34 +08:00 · 5684 次点击
    这是一个创建于 3278 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我司有好几个proxy可以用,但是都不太稳定。
    我想的就是假设有n个Proxy,在爬取失败的时候首先自己重试3次。如果重试失败就切换到下一个proxy。如果成功就继续使用当前的proxy,如果失败就一直切换代理直到没有可用的代理。如果最终还是失败了,就以某种方式记录一下,下次重新爬一遍。


    不知道我的想法在scrapy之中如何实现?
    如果有例子代码就更好了~

    最终目的就是保证目标url能被正确的爬出结果。如果有其他更好的解决方案也麻烦说一下~
    多谢!
    10 条回复    2015-05-09 10:01:09 +08:00
    AlloVince
        1
    AlloVince  
       2015-05-07 11:21:31 +08:00   ❤️ 1
    RangerWolf
        2
    RangerWolf  
    OP
       2015-05-07 11:26:39 +08:00
    @AlloVince 非常感谢!正是我需要的!
    bengtuo
        3
    bengtuo  
       2015-05-07 11:48:17 +08:00
    Scrapy 还是不够好
    bengtuo
        4
    bengtuo  
       2015-05-07 11:48:27 +08:00
    要写 太多的代码
    zts1993
        5
    zts1993  
       2015-05-07 12:08:24 +08:00
    写一个DOWNLOADER_MIDDLEWARES
    binux
        6
    binux  
       2015-05-07 12:13:04 +08:00
    squid
    RangerWolf
        7
    RangerWolf  
    OP
       2015-05-07 13:28:37 +08:00
    @binux 还得自己维护一个squid就太繁重了
    RangerWolf
        8
    RangerWolf  
    OP
       2015-05-07 13:29:19 +08:00
    @bengtuo 那有什么推荐的吗?
    要写的代码多一点没什么,重要的是能有解决方案。 如果能在网上找到相应的解决方案的代码就更好了
    messense
        9
    messense  
       2015-05-07 16:35:37 +08:00   ❤️ 1
    我用的修改自 scrapy-proxies 的 RetryMiddleware,禁用 Scrapy 自带的 RetryMiddleware

    https://github.com/messense/douappbook/blob/master/douappbook/middlewares.py#L10
    ultimate010
        10
    ultimate010  
       2015-05-09 10:01:09 +08:00   ❤️ 1
    我以前就是把代理ip存到redis中,每次抓取查询换ip,封装下使用很方便。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2882 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 07:18 · PVG 15:18 · LAX 00:18 · JFK 03:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.