-4
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)

I have tried numerous things to get the code to run again after so many seconds but everything I try gives me errors(windows user)

import urllib2 
import time 
def executeSomething(): 
    page = urllib2.urlopen('127.0.0.1:5000/') 
    page_content = page.read() with open('index.html', 'w') as fid:
        fid.write(page_content) 
        time.sleep(60) 

while True: 
    executeSomething()
joel goldstick
  • 4,393
  • 6
  • 30
  • 46
NO nON
  • 1
  • 1
  • i tried http://stackoverflow.com/questions/22715086/scheduling-python-script-to-run-every-hour-accurately and http://stackoverflow.com/questions/474528/what-is-the-best-way-to-repeatedly-execute-a-function-every-x-seconds-in-python maybe i just put the code in wrong – NO nON Jul 18 '16 at 08:17
  • [code]import urllib2 import time def executeSomething(): 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(60) while True: executeSomething()[/code] – NO nON Jul 18 '16 at 08:18
  • Welcome to SO. You can edit your question to add what you tried. This is better than posting it as a comment, as it gets more attention there. – luator Jul 18 '16 at 08:26

1 Answers1

0

Use 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)
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • thank you so much..I was doing the order wrong – NO nON Jul 18 '16 at 08:22
  • @NOnON You're welcome. If this answered your question, then you should accept the answer. See [How does accepting an answer work?](http://meta.stackexchange.com/a/5235/158075) – Martin Thoma Jul 18 '16 at 08:31