我使用wget下载网站内容,但是wget是一个一个下载文件的。
我怎么能让wget下载使用4个同时连接?
我使用wget下载网站内容,但是wget是一个一个下载文件的。
我怎么能让wget下载使用4个同时连接?
当前回答
如果你在做递归下载,你还不知道所有的url, wget是完美的。
如果您已经有了想要下载的每个URL的列表,那么可以跳过下面的cURL。
使用Wget递归地进行多个同时下载(未知的url列表)
# Multiple simultaneous donwloads
URL=ftp://ftp.example.com
for i in {1..10}; do
wget --no-clobber --recursive "${URL}" &
done
上面的循环将启动10个wget,每个wget都递归地从同一个网站下载,但是它们不会重叠或下载同一文件两次。
使用——no-clobber可以防止10个wget进程中的每个进程两次下载同一个文件(包括完整的相对URL路径)。
& fork每个wget到后台,允许你运行多个同时下载从同一个网站使用wget。
从url列表中使用curl
如果你已经有了一个想要下载的url列表,curl -Z是并行的curl,默认一次运行50个下载。
然而,对于curl,列表必须是这样的格式:
url = https://example.com/1.html
-O
url = https://example.com/2.html
-O
因此,如果您已经有一个要下载的url列表,只需格式化该列表,然后运行cURL
cat url_list.txt
#https://example.com/1.html
#https://example.com/2.html
touch url_list_formatted.txt
while read -r URL; do
echo "url = ${URL}" >> url_list_formatted.txt
echo "-O" >> url_list_formatted.txt
done < url_list.txt
使用curl从url列表中并行下载:
curl -Z --parallel-max 100 -K url_list_formatted.txt
例如,
$ curl -Z --parallel-max 100 -K url_list_formatted.txt
DL% UL% Dled Uled Xfers Live Qd Total Current Left Speed
100 -- 2512 0 2 0 0 0:00:01 0:00:01 --:--:-- 1973
$ ls
1.html 2.html url_list_formatted.txt url_list.txt
其他回答
考虑使用正则表达式或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的大文件。
我强烈建议使用httrack。
例如:httrack -v -w http://example.com/
默认情况下,它将使用8个同时连接创建镜像。Httrack有很多游戏地点可供选择。看一看。
我发现(可能) 一个解决方案
In the process of downloading a few thousand log files from one server to the next I suddenly had the need to do some serious multithreaded downloading in BSD, preferably with Wget as that was the simplest way I could think of handling this. A little looking around led me to this little nugget: wget -r -np -N [url] & wget -r -np -N [url] & wget -r -np -N [url] & wget -r -np -N [url] Just repeat the wget -r -np -N [url] for as many threads as you need... Now given this isn’t pretty and there are surely better ways to do this but if you want something quick and dirty it should do the trick...
注意:选项-N使wget只下载“更新的”文件,这意味着它不会覆盖或重新下载文件,除非它们在服务器上的时间戳发生了变化。
尝试pcurl
http://sourceforge.net/projects/pcurl/
使用curl代替wget,并行下载10段。
为每个链接调用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)