需要解决方案urllib2

时间:2016-04-09 13:33:19

标签: python linux raspberry-pi urllib2 python-2.x

我正在使用url lib2,我需要一个帮助。 当我从网站上获得我需要的信息时,它工作正常,但如果网站上的信息发生变化,结果仍然相同,我认为我必须找到一种方法来清理"缓存&#34 ;或者" lib.close" ......我不知道......有人可以帮助我吗?谢谢

以下是代码:

import urllib2            

url = 'http://website.com'

response = urllib2.urlopen(url)
webContent = response.read()

string = webContent.find('***')
alert = webContent[string+11:]

webContent = alert
string = webContent.find('***')
alert = webContent[:string]
alert = alert.replace('</strong>',' ')

print alert

1 个答案:

答案 0 :(得分:0)

urllib2不进行缓存。要么涉及HTTP代理,要么在服务器端进行缓存。

检查响应标头。 X-CacheX-Cache-Lookup表示您通过代理连接。