我使用wget下载网站内容,但是wget是一个一个下载文件的。

我怎么能让wget下载使用4个同时连接?


当前回答

我使用gnu并行

cat listoflinks.txt | parallel --bar -j ${MAX_PARALLEL:-$(nproc)} wget -nv {}

cat会将行分隔的url列表管道到parallel ——bar标志将显示并行执行进度条 MAX_PARALLEL env var是并行下载的最大数量,请谨慎使用,这里默认是当前cpu的数量

提示:使用——dry-run来查看如果执行命令会发生什么。 cat listfllinks .txt | parallel——dry-run——bar -j ${MAX_PARALLEL} wget -nv {}

其他回答

Wget不能在多个连接中下载,相反,您可以尝试使用其他程序,如aria2。

使用咏叹调2:

aria2c -x 16 [url]
#          |
#          |
#          |
#          ----> the number of connections 

http://aria2.sourceforge.net

make可以很容易地并行化(例如,make -j 4)。例如,这是一个简单的Makefile,我正在使用wget并行下载文件:

BASE=http://www.somewhere.com/path/to
FILES=$(shell awk '{printf "%s.ext\n", $$1}' filelist.txt)
LOG=download.log

all: $(FILES)
    echo $(FILES)

%.ext:
    wget -N -a $(LOG) $(BASE)/$@

.PHONY: all
default: all

正如其他海报所提到的,我建议你看一看aria2。Ubuntu 1.16.1版本的手册页:

aria2 is a utility for downloading files. The supported protocols are HTTP(S), FTP, BitTorrent, and Metalink. aria2 can download a file from multiple sources/protocols and tries to utilize your maximum download bandwidth. It supports downloading a file from HTTP(S)/FTP and BitTorrent at the same time, while the data downloaded from HTTP(S)/FTP is uploaded to the BitTorrent swarm. Using Metalink's chunk checksums, aria2 automatically validates chunks of data while downloading a file like BitTorrent.

您可以使用-x标志来指定每个服务器的最大连接数(默认为1):

aria2c -x 16 [url] 

如果同一文件可从多个位置下载,则可以选择从所有位置下载。使用-j标志指定每个静态URI的最大并行下载数量(默认为5)。

aria2c -j 5 [url] [url2]

更多信息请访问http://aria2.sourceforge.net/。对于使用信息,手册页是真正的描述性的,并在底部有一个小节提供了使用示例。在线版本可以在http://aria2.sourceforge.net/manual/en/html/README.html上找到。

另一个可以做到这一点的程序是axel。

axel -n <NUMBER_OF_CONNECTIONS> URL

对于基本的HTTP认证,

axel -n <NUMBER_OF_CONNECTIONS> "user:password@https://domain.tld/path/file.ext"

Ubuntu手册页。