如何“wget”文本文件中的 URL 列表?
How to `wget` a list of URLs in a text file?
假设我在一个位置有一个包含数百个 URL 的文本文件,例如
http://url/file_to_download1.gz
http://url/file_to_download2.gz
http://url/file_to_download3.gz
http://url/file_to_download4.gz
http://url/file_to_download5.gz
....
使用 wget
下载这些文件的正确方法是什么?我怀疑有像 wget -flag -flag text_file.txt
这样的命令
尝试:
wget -i text_file.txt
(检查 man wget)
快速 man wget
给我以下内容:
[..]
-i file
--input-file=file
Read URLs from a local or external file. If - is specified as file, URLs are read from the standard input. (Use ./- to read from a file literally named -.)
If this function is used, no URLs need be present on the command line. If there are URLs both on the command line and in an input file, those on the command lines will be the first ones to be retrieved. If --force-html is not specified, then file should consist of a series of URLs, one per line.
[..]
所以:wget -i text_file.txt
如果您还想保留原始文件名,请尝试:
wget --content-disposition --trust-server-names -i list_of_urls.txt
如果您使用的是 OpenWrt 或使用某些旧版本的 wget,它不会为您提供 -i
选项:
#!/bin/bash
input="text_file.txt"
while IFS= read -r line
do
wget $line
done < "$input"
此外,如果您没有 wget
,您可以使用 curl
或任何您用来下载单个文件的工具。
运行 它与
并行
cat text_file.txt | parallel --gnu "wget {}"
假设我在一个位置有一个包含数百个 URL 的文本文件,例如
http://url/file_to_download1.gz
http://url/file_to_download2.gz
http://url/file_to_download3.gz
http://url/file_to_download4.gz
http://url/file_to_download5.gz
....
使用 wget
下载这些文件的正确方法是什么?我怀疑有像 wget -flag -flag text_file.txt
尝试:
wget -i text_file.txt
(检查 man wget)
快速 man wget
给我以下内容:
[..]
-i file
--input-file=file
Read URLs from a local or external file. If - is specified as file, URLs are read from the standard input. (Use ./- to read from a file literally named -.)
If this function is used, no URLs need be present on the command line. If there are URLs both on the command line and in an input file, those on the command lines will be the first ones to be retrieved. If --force-html is not specified, then file should consist of a series of URLs, one per line.
[..]
所以:wget -i text_file.txt
如果您还想保留原始文件名,请尝试:
wget --content-disposition --trust-server-names -i list_of_urls.txt
如果您使用的是 OpenWrt 或使用某些旧版本的 wget,它不会为您提供 -i
选项:
#!/bin/bash
input="text_file.txt"
while IFS= read -r line
do
wget $line
done < "$input"
此外,如果您没有 wget
,您可以使用 curl
或任何您用来下载单个文件的工具。
运行 它与
并行cat text_file.txt | parallel --gnu "wget {}"