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

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


当前回答

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

其他回答

使用咏叹调2:

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

http://aria2.sourceforge.net

尝试pcurl

http://sourceforge.net/projects/pcurl/

使用curl代替wget,并行下载10段。

您可以使用xargs

-P是进程数,例如设置-P 4,将同时下载4个链接,如果设置-P 0, xargs将启动尽可能多的进程,并下载所有的链接。

cat links.txt | xargs -P 4 -I{} wget {}

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

axel -n <NUMBER_OF_CONNECTIONS> URL

对于基本的HTTP认证,

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

Ubuntu手册页。

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