python - 获取网页的当前版本

标签 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.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/

相关文章:

python - 逻辑函数错误分类

linux - 卸载 ("/proc") 挂载命名空间 "Invalid Argument"错误的系统调用

Linux bash 脚本文件连接

c++ - 使用 C++ 在 NxN 数组中查找 M 个最大元素的优化方法

python - 用Scrapy抓取ajax页面?

python - NDB 查询在结构化属性上使用过滤器,这也是重复的?

python - 为 python : "no module named ' hdbscan'"error 安装 hdbscan 包时出现问题

jsp - tomcat 服务缓存别名

php - 缓存包含在 PHP 中以供迭代重用

python - Pandas _metadata of DataFrame 持久化错误