我想每隔60秒获取相同的url,但是当我在计时器线程中使用我的get_html()函数时,它不刷新页面更新,总是返回相同的数据,这里是我的代码的摘录:
import urllib2
from HTMLParser import HTMLParser
import threading
class data():
def get_html(self):
proxy = urllib2.ProxyHandler({'http': 'http://'+self.proxy_username+
':'+self.proxy_password+'@'+self.proxy_addres+':'+self.proxy_port})
auth = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
urllib2.install_opener(opener)
header = {"pragma-directive" : "no-cache"}
req = urllib2.Request('http://xxxxx', headers=header)
conn = urllib2.urlopen(req)
return_str = conn.read()
conn.close()
opener.close()
par = MyHTMLParser()
par.feed(return_str)
html_data = par.get_data()
return html_data
def update(self):
check_data = data()
html_data = check_data.get_html()
print html_data
threading.Timer(60, update).start()