Wget:有选择地和递归地下载文件?

T. *_*aio 6 download wget recursive directory-structure http

关于wget、子文件夹和 index.html 的问题。

假设我在“travels/”文件夹中,这是在“website.com”中:“website.com/travels/”。

文件夹“travels/”包含很多文件和其他(子)文件夹:“website.com/travels/list.doc”、“website.com/travels/cover.png”、“website.com/travels/[1990” ] America/" , "website.com/travels/[1994] Japan/", 等等...

如何仅下载位于所有子文件夹中的所有“.mov”和“.jpg”?我不想从“travels/”中选择文件(例如不是“website.com/travels/list.doc”)

我发现一个wget命令(在 Unix&Linux Exchange 上,我不记得讨论了什么)能够从子文件夹下载只有它们的“index.html”,而不是其他内容。为什么只下载索引文件?

小智 8

此命令将仅从给定网站下载图像和电影:

wget -nd -r -P /save/location -A jpeg,jpg,bmp,gif,png,mov "http://www.somedomain.com"
Run Code Online (Sandbox Code Playgroud)

根据wget 人的说法:

-nd prevents the creation of a directory hierarchy (i.e. no directories).

-r enables recursive retrieval. See Recursive Download for more information.

-P sets the directory prefix where all files and directories are saved to.

-A sets a whitelist for retrieving only certain file types. Strings and patterns are accepted, and both can be used in a comma separated list (as seen above). See Types of Files for more information.
Run Code Online (Sandbox Code Playgroud)

如果你想下载子文件夹,你需要使用 flag --no-parent,类似于这个命令:

wget -r -l1 --no-parent -P /save/location -A jpeg,jpg,bmp,gif,png,mov "http://www.somedomain.com"

-r: recursive retrieving
-l1: sets the maximum recursion depth to be 1
--no-parent: does not ascend to the parent; only downloads from the specified subdirectory and downwards hierarchy
Run Code Online (Sandbox Code Playgroud)

关于 index.html 网页。一旦该标志-A包含在命令中wget,它将被排除,因为该标志将强制wget下载特定类型的文件,这意味着如果html要下载的接受文件列表中未包含该标志(即标志A),则不会下载并将wget在终端中输出以下消息:

Removing /save/location/default.htm since it should be rejected.
Run Code Online (Sandbox Code Playgroud)

wget可以下载特定类型的文件,例如(jpg、jpeg、png、mov、avi、mpeg 等),当这些文件存在于提供给wget例如的 URL 链接中时:

假设我们想从这个网站下载 .zip 和 .chd 文件

在此链接中有文件夹和 .zip 文件(滚动到最后)。现在,假设我们想运行这个命令:

wget -r --no-parent -P /save/location -A chd,zip "https://archive.org/download/MAME0.139_MAME2010_Reference_Set_ROMs_CHDs_Samples/roms/"
Run Code Online (Sandbox Code Playgroud)

此命令将下载 .zip 文件,同时为 .chd 文件创建一个空文件夹。

为了下载 .chd 文件,我们需要提取空文件夹的名称,然后将这些文件夹名称转换为其实际 URL。然后,将所有感兴趣的 URL 放在一个文本文件中file.txt,最后将这个文本文件提供给wget,如下所示:

wget -r --no-parent -P /save/location -A chd,zip -i file.txt
Run Code Online (Sandbox Code Playgroud)

前面的命令将查找所有 chd 文件。