我使用wget下载网站内容,但是wget是一个一个下载文件的。
我怎么能让wget下载使用4个同时连接?
我使用wget下载网站内容,但是wget是一个一个下载文件的。
我怎么能让wget下载使用4个同时连接?
当前回答
我强烈建议使用httrack。
例如:httrack -v -w http://example.com/
默认情况下,它将使用8个同时连接创建镜像。Httrack有很多游戏地点可供选择。看一看。
其他回答
由于还没有提到GNU并行,让我给出另一种方式:
cat url.list | parallel -j 8 wget -O {#}.html {}
考虑使用正则表达式或FTP Globbing。通过这种方法,您可以使用不同的文件名起始字符组多次启动wget,这取决于它们出现的频率。
这是我如何在两个NAS之间同步文件夹的例子:
wget --recursive --level 0 --no-host-directories --cut-dirs=2 --no-verbose --timestamping --backups=0 --bind-address=10.0.0.10 --user=<ftp_user> --password=<ftp_password> "ftp://10.0.0.100/foo/bar/[0-9a-hA-H]*" --directory-prefix=/volume1/foo &
wget --recursive --level 0 --no-host-directories --cut-dirs=2 --no-verbose --timestamping --backups=0 --bind-address=10.0.0.11 --user=<ftp_user> --password=<ftp_password> "ftp://10.0.0.100/foo/bar/[!0-9a-hA-H]*" --directory-prefix=/volume1/foo &
第一个wget同步所有以0,1,2…开头的文件/文件夹。F, G, H和第二个线程同步所有其他内容。
这是在带有一个10G以太网端口(10.0.0.100)的NAS和带有两个1G以太网端口(10.0.0.10和10.0.0.11)的NAS之间进行同步的最简单方法。我通过——bind-address将两个wget线程绑定到不同的以太网端口,并通过在每行末尾放置&将它们称为并行。通过这种方式,我能够复制2x 100mb /s = 200 MB/s的大文件。
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
为每个链接调用Wget并将其设置为在后台运行。
我尝试了这段Python代码
with open('links.txt', 'r')as f1: # Opens links.txt file with read mode
list_1 = f1.read().splitlines() # Get every line in links.txt
for i in list_1: # Iteration over each link
!wget "$i" -bq # Call wget with background mode
参数:
b - Run in Background
q - Quiet mode (No Output)
正如其他海报所提到的,我建议你看一看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上找到。