1

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

0 に答える 0