我正在嘗試使用 wget 從 sourceforge 下載文件,但眾所周知,我們必須單擊下載按鈕,然後等待它自動下載。如何使用 wget 下載這種類型的檔案?
但是在該 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'