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

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


当前回答

我强烈建议使用httrack。

例如:httrack -v -w http://example.com/

默认情况下,它将使用8个同时连接创建镜像。Httrack有很多游戏地点可供选择。看一看。

其他回答

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

为每个链接调用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)

为了加快文件下载速度,Wget不支持多个套接字连接。

我想我们可以给出比格里安更好的答案。

正确的方法是使用aria2。

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

官方文档:

-x,——max-connection-per-server=NUM:每次下载到一台服务器的最大连接数。取值范围:1 ~ 16。默认值:1

-s,——split=N:使用N个连接下载文件。如果提供了超过N个uri,则使用前N个uri,其余url用于备份。如果给出的uri少于N个,则这些url将被使用不止一次,以便同时建立总共N个连接。到同一主机的连接数量由——max-connection-per-server选项限制。另参见——min-split-size选项。取值范围:1-*默认值:5

use

aria2c -x 10 -i websites.txt >/dev/null 2>/dev/null &

在sites.txt中每行放一个url,例如:

https://www.example.com/1.mp4
https://www.example.com/2.mp4
https://www.example.com/3.mp4
https://www.example.com/4.mp4
https://www.example.com/5.mp4

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