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

如何让 for 循环在指定时间仍然结束的话自动 continue,并重新计数?

  •  
  •   Rudefish · May 29, 2018 · 3224 views
    This topic created in 3043 days ago, the information mentioned may be changed or developed.

    写了个 tumblr 的视频爬虫,vpn 掉了后即使重新连上网速恢复了,下载速度还是零点几 KB,用什么办法让指定时间后自动重新开始这个 for 循环?

    xpresslink
        1
    xpresslink  
       May 29, 2018
    import time
    while True:
    ****for xxxx
    ********do xxx
    ****time.sleep(60)
    Rudefish
        2
    Rudefish  
    OP
       May 29, 2018
    @xpresslink 你写的这个 for 循环不执行完,time.sleep 应该不会执行吧
    golmic
        3
    golmic  
       May 29, 2018
    while 1
    start = now
    for
    if now - start > 60
    break
    do
    Rudefish
        4
    Rudefish  
    OP
       May 29, 2018
    @golmic 卡住的地方应该是 video = requests.get ()这块,这个判断语句放在里面应该不会执行到吧
    golmic
        5
    golmic  
       May 29, 2018
    @Rudefish #4 requests.get(timeout=1)
    lniwn
        6
    lniwn  
       May 29, 2018
    aiohttp + asyncio.Timeout ?
    bigpigeon
        7
    bigpigeon  
       May 30, 2018
    我记得 python 的 req 模块有 timeout 参数的,用 scrapy 也应该有 timeout 参数的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2585 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 09:46 · PVG 17:46 · LAX 02:46 · JFK 05:46
    ♥ Do have faith in what you're doing.