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

srcapy 已经有了一个代理池,写入了中间件,这个代理是随机切换的,也是秒切 ip,请问一下,如何做到请求 10 次再切换 ip?

  •  1
     
  •   Mrrrrr10 · Sep 16, 2018 · 3247 views
    This topic created in 2821 days ago, the information mentioned may be changed or developed.

    请教有经验的大佬,给我说一说,谢谢啦

    7 replies    2018-09-18 14:25:03 +08:00
    lihongjie0209
        1
    lihongjie0209  
       Sep 16, 2018
    最简单, 你给每个 IP 使用的时候计数一下, 切换的时候检测不就好了
    freemoon
        2
    freemoon  
       Sep 16, 2018
    scrapy 的 extension 中间件可以了解一下。
    Mrrrrr10
        3
    Mrrrrr10  
    OP
       Sep 16, 2018
    @lasuar 怎么重置次数呢
    Mrrrrr10
        4
    Mrrrrr10  
    OP
       Sep 16, 2018
    @lihongjie0209 怎么重置次数
    chinvo
        5
    chinvo  
       Sep 16, 2018 via iPhone
    第十次的时候把你的变量改为 0

    既然都自己写中间件了加个逻辑不难啊
    yuan10
        6
    yuan10  
       Sep 17, 2018   ❤️ 1
    中间件里写个__init__方法,定义一个属性 self.cnt ,process_request 里计数,cnt 达到 10 就置 0,同时切 ip,这应该很简单吧
    Mrrrrr10
        7
    Mrrrrr10  
    OP
       Sep 18, 2018
    @yuan10 老哥我爱你
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2831 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 05:56 · PVG 13:56 · LAX 22:56 · JFK 01:56
    ♥ Do have faith in what you're doing.