2

我使用 python 的 urllib 库每​​ 5 秒检查一个网页的更新。但是在我运行程序几个小时后,似乎 urllib.open(url) 只是返回了过时的数据。它通常会延迟 5-10 分钟。我需要你的帮助。

    urlItem = urllib.urlopen("http://ka.game.163.com/")
    htmlSource = urlItem.read()
    urlItem.close()
4

1 回答 1

0

This looks like a caching issue. A cache is used to optimize communication so common requested data wont need to be requested all the time.

When you call urllib.open it uses under the hood the urlib.retrieve function. This function caches data locally, so to avoid this caching you should call urllib.urlcleanup before each call to urllib.open. This is stated in the documentation

Also, your question hits the same issue as described in this one, consider looking it

于 2013-06-10T14:49:52.753 回答