如何使用wget下载文件,页面让你等待下载?

如何使用wget下载文件,页面让你等待下载?

我正在尝试使用 wget 从 sourceforge 下载文件,但众所周知,我们必须单击下载按钮,然后等待它自动下载。如何使用 wget 下载这种类型的文件?

我正在尝试下载这个:http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.8.1/bitcoin-0.8.1-linux.tar.gz/download

但是在该 url 链接上执行 wget 不会获取该文件,因为该文件是通过浏览器自动加载的。

答案1

我建议使用curl而不是这样做wget。它可以使用开关-L-J和 来遵循重定向-O

curl -O -J -L http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.8.1/bitcoin-0.8.1-linux.tar.gz/download

开关定义

-O/--remote-name
  Write output to a local file named like the remote file we get. 
  (Only the file part of the remote  file  is  used, the path is cut off.)

-L/--location
  (HTTP/HTTPS)  If  the  server  reports that the requested page has moved 
  to a different location (indicated with a Location: header and a 3XX 
  response code), this option will make curl redo the request on the new 
  place.  If  used together  with  -i/--include  or -I/--head, headers from 
  all requested pages will be shown. When authentication is used, curl only 
  sends its credentials to the initial host. If a redirect takes curl to a 
  different host, it  won't be  able  to  intercept  the  user+password. 
  See also --location-trusted on how to change this. You can limit the
  amount of redirects to follow by using the --max-redirs option.

-J/--remote-header-name
  (HTTP) This option tells the -O/--remote-name option to  use  the  
  server-specified  Content-Disposition  filename instead of extracting a 
  filename from the URL.

请参阅卷曲手册页更多细节。

答案2

wget可以使用--content-disposition对某些文件下载 CGI 程序有用的选项,这些程序使用“Content-Disposition”标头来描述下载文件的名称。

在示例中:

wget --user-agent=Mozilla --content-disposition -E -c http://example.com/

对于更复杂的解决方案(例如需要授权),请使用 cookie 文件 ( --load-cookies file) 来模拟您的会话。

答案3

我不确定wget您和 sourceforge 之间存在哪个版本的操作系统和任何代理,但当wget我删除“/download”并将其保留为文件扩展名时下载了该文件。

我不想在整个会话中淹没帖子或粘贴,但在传输开始之前我收到了 302 然后 200 状态代码。当你尝试时会发生什么wget

Resolving downloads.sourceforge.net... 216.34.181.59
Connecting to downloads.sourceforge.net|216.34.181.59|:80... connected.
HTTP request sent, awaiting response... 302 Found

[snipped for brevity]

HTTP request sent, awaiting response... 200 OK
Length: 13432789 (13M) [application/x-gzip]
Saving to: `download'

相关内容