开发者

Python won't refresh URL to receive new forex ticker data

开发者 https://www.devze.com 2022-12-12 14:20 出处:网络
I am trying to save updated Forex ticker data from this website: http://fo开发者_如何学Crex.offers4u.biz/TickDBReadDB.php?p=EURUSD

I am trying to save updated Forex ticker data from this website: http://fo开发者_如何学Crex.offers4u.biz/TickDBReadDB.php?p=EURUSD

just hit refresh to update the ticker.

when I use my little python script, it saves the text once, but if i run it again, it makes a new file with the same old data. How can I add a "cachebreaker" so that python can read the new data from the old URL?

import urllib2, time

filename = 'EURUSD ' + str(time.asctime()) + '.txt'

myfile = open(filename, 'w')

page = urllib2.urlopen("http://forex.offers4u.biz/TickDBReadDB.php?p=EURUSD?")

for line in page:
    myfile.write(line)

myfile.close()
page.close()


urllib2 doesn't do any caching. Are you going through a proxy? Or the server may be caching.

Try using a Cache-Control header described here, section 14.9

EDIT: Mind you, the most recent data on that page is from 2009.11.16 20:47:37. Are you sure it's still being actively updated?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号