如何在 Wget 或 Python 中获取网页的当前版本?我需要完全关闭缓存。
我正在尝试编写代码来下载 http://robocademy.com/courses/arduino/get_code/每一秒。使用 Python 的 urllib 和 Wget,我无法像在 Chrome 中那样获取当前文件。 我试过了
wget --cache=off --user-agent="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" http://robocademy.com/courses/arduino/get_code/
和带有 urllib.urlcleanup 的 urllib
chrome 中的响应 header :
Accept-Ranges:bytes
Age:0
Connection:keep-alive
Content-Encoding:gzip
Content-Length:449
Content-Type:text/plain
Date:Wed, 28 Nov 2012 23:20:24 GMT
Server:nginx
Vary:Accept-Encoding
Via:1.1 varnish
X-Varnish:400211059
Wget 中的响应头
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/plain
Keep-Alive: timeout=20
Vary: Accept-Encoding
Transfer-Encoding: chunked
Date: Wed, 28 Nov 2012 23:22:20 GMT
X-Varnish: 400216320 400212892
Age: 76
Via: 1.1 varnish
Connection: keep-alive
最佳答案
您可以尝试将 --no-cache
添加到 wget。根据手册:
Disable server-side cache. In this case, Wget will send the remote server an appropriate directive (‘Pragma: no-cache’) to get the file from the remote service, rather than returning the cached version. This is especially useful for retrieving and flushing out-of-date documents on proxy servers.
Caching is allowed by default.
cache=off
应该放在 wgetrc
文件中。
对于 Python 你可以考虑这个 answer .
关于python - 获取网页的当前版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13616340/