如何使用wget/curl下载给定网页上的.zip文件的所有链接?

uye*_*tch 76 curl wget download

一个页面包含一组.zip文件的链接,所有这些文件都要我下载.我知道这可以通过wget和curl来完成.怎么做?

cre*_*ive 115

命令是:

wget -r -np -l 1 -A zip http://example.com/download/
Run Code Online (Sandbox Code Playgroud)

选项含义:

-r,  --recursive          specify recursive download.
-np, --no-parent          don't ascend to the parent directory.
-l,  --level=NUMBER       maximum recursion depth (inf or 0 for infinite).
-A,  --accept=LIST        comma-separated list of accepted extensions.
Run Code Online (Sandbox Code Playgroud)

  • 如果你不想创建任何额外的目录(即所有文件都在根文件夹中),`-nd`(无目录)标志很方便. (14认同)
  • 如果文件与起始 URL 不在同一目录中,您可能需要去掉 `-np`。如果它们在不同的主机上,您将需要`--span-host`。 (2认同)

K.-*_*Aye 70

以上解决方案对我不起作用.对我来说只有这个有效:

wget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off [url of website]
Run Code Online (Sandbox Code Playgroud)

选项含义:

-r            recursive
-l1           maximum recursion depth (1=use only this directory)
-H            span hosts (visit other hosts in the recursion)
-t1           Number of retries
-nd           Don't make new directories, put downloaded files in this one
-N            turn on timestamping
-A.mp3        download only mp3s
-erobots=off  execute "robots.off" as if it were a part of .wgetrc
Run Code Online (Sandbox Code Playgroud)

  • 资料来源:http://www.commandlinefu.com/commands/view/12498/download-all-music-files-off-of-a-website-using-wget (2认同)

小智 6

对于具有一些并行魔法的其他场景,我使用:

curl [url] | grep -i [filending] | sed -n 's/.*href="\([^"]*\).*/\1/p' |  parallel -N5 wget -
Run Code Online (Sandbox Code Playgroud)