python - 需要一个解决方案 urllib2

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

我正在使用 url lib2,我需要帮助。 当我从网站上得到我需要的信息时,它工作正常,但是如果网站上的信息改变了,结果还是一样,我想我必须找到一种清理“缓存”或“库”的方法.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

最佳答案

urllib2 不做缓存。要么涉及 HTTP 代理,要么缓存发生在服务器端。

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

关于python - 需要一个解决方案 urllib2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36517448/

相关文章:

python - 如何从 C++ 调用 Python

c - 当两者都是 USB 驱动器时,如何在 c 中检查/dev/sda 下到底是什么以及/dev/sdb 下是什么

ssh - 关闭 ssh session 而不在远程计算机上注销

python - 从下拉菜单python中的每个选项中抓取表格

c++ - 如何在c++中直接使用addr2line

database - 如何到 "explore"组服务器?

linux - 网络管理员未列出 wifi

python - 单元测试 get_absolute_url django

python - Telepot 中的 sendPhoto() 对我的机器人不起作用

python - 我如何构造这个 while 循环,以便它检查两个条件并在必要时终止它