获取当前版本的网页

时间:2012-11-28 23:33:26

标签: python linux caching wget

如何在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 with urllib.urlcleanup

chrome中的响应标头:

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

1 个答案:

答案 0 :(得分:-1)

您可以尝试将--no-cache添加到wget。根据手册:

  

禁用服务器端缓存。在这种情况下,Wget将向远程服务器发送适当的指令('Pragma:no-cache')以从远程服务获取文件,而不是返回缓存版本。这对于检索和刷新代理服务器上的过期文档特别有用。

     

默认情况下允许缓存。

cache=off应该放在wgetrc文件中。

对于Python,您可以考虑这个answer