wget 破坏了内容配置

adl*_*tta 5 linux curl wget content-disposition

我正在尝试从以下网站下载通过 Content-Disposition:attachment 发送的 kml 文件:

\n\n
http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia\n
Run Code Online (Sandbox Code Playgroud)\n\n

将 wget 和curl 与命令一起使用:

\n\n
wget --content-disposition http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia\n
Run Code Online (Sandbox Code Playgroud)\n\n

\n\n
curl -O -J -L http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia\n
Run Code Online (Sandbox Code Playgroud)\n\n

然而,它不保存正在发送的文件,而是仅保存 html 内容,并且在传输结束时它会卡住。终端返回为:

\n\n
$wget --content-disposition http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia\n[1] 32260\n[2] 32261\n[3] 32262\nwork@Aspire-V3-471:~$ --2016-05-13 19:37:54--  http://waterwatch.usgs.gov/index.php?m=real\nResolving waterwatch.usgs.gov (waterwatch.usgs.gov)... 2001:49c8:0:126c::56, 137.227.242.56\nConnecting to waterwatch.usgs.gov (waterwatch.usgs.gov)|2001:49c8:0:126c::56|:80... connected.\nHTTP request sent, awaiting response... 200 OK\nLength: unspecified [text/html]\nSaving to: \xe2\x80\x98index.php?m=real.5\xe2\x80\x99\n\n    [  <=>                                                                                                                                                  ] 41.637       174KB/s   in 0,2s   \n\n2016-05-13 19:37:55 (174 KB/s) - \xe2\x80\x98index.php?m=real.5\xe2\x80\x99 saved [41637]\n
Run Code Online (Sandbox Code Playgroud)\n\n

他们变得如此,我需要按 Ctrl+C。\n因为我得到的标题是

\n\n
HTTP/1.1 200 OK\nDate: Sat, 14 May 2016 00:19:21 GMT\nContent-Disposition: attachment; filename="real_ia.kml"\nKeep-Alive: timeout=5, max=100\nConnection: Keep-Alive\nTransfer-Encoding: chunked\nContent-Type: application/vnd.google-earth.kml+xml\nX-Frame-Options: SAMEORIGIN\n
Run Code Online (Sandbox Code Playgroud)\n\n

我希望下载“real_ia.kml”文件。\n使用curl 命令给出类似的结果。

\n\n

为什么会卡住并且只下载 HTML 内容?

\n

Rus*_*nov 3

这些&符号被解释为 shell 特殊字符,它导致命令在后台运行(fork)。所以你应该转义或引用它们:

curl -O -J -L 'http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia'
Run Code Online (Sandbox Code Playgroud)

在上面的命令中,我们使用了完整引用

输出中的以下几行意味着三个命令被分叉到后台:

[1] 32260
[2] 32261
[3] 32262
Run Code Online (Sandbox Code Playgroud)

左边的数字(括号内)是职位编号。您可以通过键入 来将作业调至前台fg N,其中N是作业编号。右边的数字是进程 ID。

  • 鲁斯兰·奥斯马诺夫,你拯救了世界!现在一切都使用命令运行:“curl -O -J -L http://waterwatch.usgs.gov/index.php?m=real\&amp;w=kml\&amp;r=us\®ions=ia”(仅在此发布到为其他人说清楚)非常感谢! (2认同)