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

Pat*_*パトシ 47 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 不会得到我的文件,因为该文件是通过浏览器自动加载的。

slm*_*slm 62

我建议使用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
Run Code Online (Sandbox Code Playgroud)

开关定义

-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.
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅curl 手册页

  • 不需要使用 curl,`wget` 可以跟随重定向,但它不会这样做,除非你从默认值增加 `--max-redirect`,出于 [安全原因](http://www.linuxquestions. org/questions/linux-software-2/wget-and-redirection-345815/) 当然是 0。 (2认同)

ken*_*orb 17

wget你可以使用--content-disposition选项,这是对一些文件的下载CGI程序有用的使用“内容处置”标题来形容下载的文件的名称应该是什么。

例如:

wget --user-agent=Mozilla --content-disposition -E -c http://example.com/
Run Code Online (Sandbox Code Playgroud)

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


小智 7

我不确定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'
Run Code Online (Sandbox Code Playgroud)