使用 wget,获取 gzipped 版本而不是实际 HTML 的正确命令是什么

jom*_*ana 22 wget

我偶然发现了这个谈论这个的网站

因此,当通过获取 gzip 版本下载整个网站时,正确的命令是什么?

我已经测试了这个命令,但我不知道 wget 是否真的得到了 gzip 版本:

wget --header="accept-encoding: gzip" -m -Dlinux.about.com -r -q -R gif,png,jpg,jpeg,GIF,PNG,JPG,JPEG,js,rss,xml,feed,.tar.gz,.zip,rar,.rar,.php,.txt -t 1 http://linux.about.com/
Run Code Online (Sandbox Code Playgroud)

Eig*_*ony 23

如果您请求 gzip 的内容(使用 accept-encoding: gzip 标头,这是正确的),那么我的理解是 wget 无法读取内容。因此,对于您点击的第一页,您将在磁盘上得到一个单独的 gzipped 文件,但没有其他内容。

即您不能使用 wget 请求 gzipped 内容并同时递归整个站点。

我认为有一个补丁允许 wget 支持此功能,但它不在默认发行版中。

如果包含 -S 标志,则可以判断 Web 服务器是否以正确类型的内容进行响应。例如,

wget -S --header="accept-encoding: gzip" wordpress.com
--2011-06-17 16:06:46--  http://wordpress.com/
Resolving wordpress.com (wordpress.com)... 72.233.104.124, 74.200.247.60, 76.74.254.126
Connecting to wordpress.com (wordpress.com)|72.233.104.124|:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Server: nginx
  Date: Fri, 17 Jun 2011 15:06:47 GMT
  Content-Type: text/html; charset=UTF-8
  Connection: close
  Vary: Accept-Encoding
  Last-Modified: Fri, 17 Jun 2011 15:04:57 +0000
  Cache-Control: max-age=190, must-revalidate
  Vary: Cookie
  X-hacker: If you're reading this, you should visit automattic.com/jobs and apply to join the fun, mention this header.
  X-Pingback: http://wordpress.com/xmlrpc.php
  Link: <http://wp.me/1>; rel=shortlink
  X-nananana: Batcache
  Content-Encoding: gzip
Length: unspecified [text/html]
Run Code Online (Sandbox Code Playgroud)

内容编码清楚地说明了 gzip,但是对于 linux.about.com(当前),

wget -S --header="accept-encoding: gzip" linux.about.com
--2011-06-17 16:12:55--  http://linux.about.com/
Resolving linux.about.com (linux.about.com)... 207.241.148.80
Connecting to linux.about.com (linux.about.com)|207.241.148.80|:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Date: Fri, 17 Jun 2011 15:12:56 GMT
  Server: Apache
  Set-Cookie: TMog=B6HFCs2H20kA1I4N; domain=.about.com; path=/; expires=Sat, 22-Sep-12 14:19:35 GMT
  Set-Cookie: Mint=B6HFCs2H20kA1I4N; domain=.about.com; path=/
  Set-Cookie: zBT=1; domain=.about.com; path=/
  Vary: *
  PRAGMA: no-cache
  P3P: CP="IDC DSP COR DEVa TAIa OUR BUS UNI"
  Cache-Control: max-age=-3600
  Expires: Fri, 17 Jun 2011 14:12:56 GMT
  Connection: close
  Content-Type: text/html
Length: unspecified [text/html]
Run Code Online (Sandbox Code Playgroud)

它正在返回文本/ html。

由于一些较旧的浏览器仍然存在 gzip 编码内容的问题,因此许多站点仅根据浏览器标识启用它。他们经常在默认情况下关闭它,只有在他们知道浏览器可以支持它时才将它打开 - 而且他们通常不将 wget 包含在该列表中。这意味着您可能会发现 wget 从不返回 gzip 内容,即使该站点似乎为您的浏览器这样做。