使用 wget 从 url 列表下载具有文件名的文件

Download files with filename from list of urls using wget

我有一个包含列表或链接的文件。

http://example.com/00001
http://example.com/00002
http://example.com/00003
http://example.com/00004

在浏览器中手动转到这些链接之一时,将自动下载一个文件。下载的文件具有该文件的唯一名称,与 url 路径不同。

我知道使用 wget -i file-of-links.txt,但是在下载时,每个文件的标题都会基于 url,而不是基于文件名。

是否有命令允许我从给定文件下载链接并使用文件名而不是 url 名称保存下载的文件?

是的。您可以使用 wget 的 --trust-server-names--content-disposition 选项来执行此操作。

--trust-server-names

If this is set to on, on a redirect the last component of the redirection URL will be used as the local file name. By default it is used the last component in the original URL

--content-disposition

if this is set to on, experimental (not fully-functional) support for Content-Disposition headers is enabled. This can currently result in extra round-trips to the server for a HEAD request, and is known to suffer from a few bugs, which is why it is not currently enabled by default.

This option is useful for some file-downloading CGI programs that use Content-Disposition headers to describe what the name of a downloaded file should be.