推荐学习书目
› 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 · 3336 views
    This topic created in 3085 days ago, the information mentioned may be changed or developed.

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

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