python 反复执行问题

2025-02-26 18:51:33
推荐回答(4个)
回答1:

你好,time模块中的:

Python 编程中使用 time 模块可以让程序休眠
 
具体方法是time.sleep(秒数),其中“秒数”以秒为单位,可以是小数,0.1秒则代表休眠100毫秒。
# 例1:循环输出休眠1秒
import time
i = 1
while i <= 3:
    print i # 输出i
    i += 1
    time.sleep(1) # 休眠1秒

# 例1:循环输出休眠100毫秒
import time
i = 1
while i <= 3:
    print i # 输出i
    i += 1
    time.sleep(0.1) # 休眠0.1秒

回答2:

python的try catch语句,或者直接try except ,except语句捕捉任何错误,在这里sleep一下就可以了

回答3:

try
[抓取网页]

except [可能会报的错]
finally
[如果出错了,sleep多久,再次运行抓取]

回答4:

用try catch