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

2018-05-29 16:46:40 +08:00
 Rudefish

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

2450 次点击
所在节点    Python
7 条回复
xpresslink
2018-05-29 17:02:02 +08:00
import time
while True:
****for xxxx
********do xxx
****time.sleep(60)
Rudefish
2018-05-29 17:08:35 +08:00
@xpresslink 你写的这个 for 循环不执行完,time.sleep 应该不会执行吧
golmic
2018-05-29 17:10:43 +08:00
while 1
start = now
for
if now - start > 60
break
do
Rudefish
2018-05-29 17:17:28 +08:00
@golmic 卡住的地方应该是 video = requests.get ()这块,这个判断语句放在里面应该不会执行到吧
golmic
2018-05-29 17:44:59 +08:00
@Rudefish #4 requests.get(timeout=1)
lniwn
2018-05-29 18:58:36 +08:00
aiohttp + asyncio.Timeout ?
bigpigeon
2018-05-30 10:15:36 +08:00
我记得 python 的 req 模块有 timeout 参数的,用 scrapy 也应该有 timeout 参数的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/458704

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX