如何使用以下代码每10秒执行一次

时间:2016-07-18 08:13:11

标签: python

google-services.json

我已经尝试了很多东西让代码在这么多秒后再次运行但是我尝试的一切都给了我错误(windows用户)

import urllib2

page = urllib2.urlopen('http://127.0.0.1:5000/')

page_content = page.read()

with open('index.html', 'w') as fid:
    fid.write(page_content)

1 个答案:

答案 0 :(得分:1)

使用time.sleep

import urllib2
import time

while True:
    page = urllib2.urlopen('http://127.0.0.1:5000/')
    page_content = page.read()
    with open('index.html', 'w') as fid:
        fid.write(page_content)
    time.sleep(10)
相关问题