字符界面下的下载工具-wget


GNU Wget是一个在网络上进行下载的简单而强大的自由软件,其本身也是GNU计划的一部分。它的名字是“World Wide Web”和“Get”的结合,同时也隐含了软件的主要功能。目前它支持通过HTTP、HTTPS,以及FTP这三个最常见的TCP/IP协议协议下载。采用C语言开发并在GPL协议下授权。
特点
支持递归下载
恰当的转换页面中的链接
生成可在本地浏览的页面镜像
支持代理服务器
GNU Wget is a free software package for retrieving files using HTTP, HTTPS and FTP, the most widely-used Internet protocols. It is a non-interactive commandline tool, so it may easily be called from scripts, cron jobs, terminals without X-Windows support, etc.
Wget has many features to make retrieving large files or mirroring entire web or FTP sites easy, including:
Can resume aborted downloads, using REST and RANGE
Can use filename wild cards and recursively mirror directories
NLS-based message files for many different languages
Optionally converts absolute links in downloaded documents to relative, so that downloaded documents may link to each other locally
Runs on most UNIX-like operating systems as well as Microsoft Windows
Supports HTTP proxies and cookies
Supports persistent HTTP connections
Unattended / background operation
Uses local file timestamps to determine whether documents need to be re-downloaded when mirroring
wget 非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性。如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕。如果是服务器中断下载过程,它会再次联到服务器上从停止的地方继续下载,这对从那些限定了链接时间的服务器上下载大文件非常有用。它可以跟踪HTML页面上的链接依次下载来创建远程服务器的本地版本,完全重建原始站点的目录结构,常被称作"递归下载"。在递归下载的时候,它遵循Robot Exclusion标准(/robots.txt),它可以在下载的同时,将链接转换成指向本地文件,以方便离线浏览。
wget和curl都支持限制下载速度,手册页中直接提到了这两个选项。
--limit-rate=amount
Limit the download speed to amount bytes per second. Amount may be expressed in bytes, kilobytes with the k suffix, or megabytes with the m suffix. For example, --limit-rate=20k will limit the retrieval rate to 20KB/s. This is useful when, for whatever reason, you don't want Wget to consume the entire available bandwidth.
例如: wget --limit-rate=423k
递归下载网站页面
以下载内核的4.x的最新文档为例(https://www.kernel.org/doc/html/v4.20/)
wget -nd -r -l1 -P /save_location -A jpeg,jpg https://www.kernel.org/doc/html/v4.20/
参数说明:
-nd prevents the creation of a directory hierarchy (i.e. no directories).
-r enables recursive retrieval. See Recursive Download for more information.
-l1 Specify recursion maximum depth level. 1 for just this directory in your case it's products.
-P sets the directory prefix where all files and directories are saved to.
-A sets a whitelist for retrieving only certain file types. Strings and patterns are accepted, and both can be used in a comma separated list (as seen above). See Types of Files for more information.
其它用法1:
wget -nH --page-requisites -R -nH -P mirrorDir https://www.kernel.org/doc/html/v4.20/
wget -r -np -k https://www.kernel.org/doc/html/v4.20/
the useful options:
-nd (no directories): download all files to the current directory
-e robots.off: ignore robots.txt files, don't download robots.txt files
-A png,jpg: accept only files with the extensions png or jpg
-m (mirror): -r --timestamping --level inf --no-remove-listing
-nc, --no-clobber: Skip download if files exist
其它用法2:
wget --execute="robots = off" --mirror --convert-links --no-parent --wait=5 <website-url>
选项解析:
wget: Simple Command to make CURL request and download remote files to our local machine.
--execute="robots = off": This will ignore robots.txt file while crawling through pages. It is helpful if you're not getting all of the files.
--mirror: This option will basically mirror the directory structure for the given URL. It's a shortcut for -N -r -l inf --no-remove-listing which means:
-N: don't re-retrieve files unless newer than local
-r: specify recursive download
-l inf: maximum recursion depth (inf or 0 for infinite)
--no-remove-listing: don't remove '.listing' files
--convert-links: make links in downloaded HTML or CSS point to local files
--no-parent: don't ascend to the parent directory
--wait=5: wait 5 seconds between retrievals. So that we don't thrash the server.
<website-url>: This is the website url from where to download the files.
wget与curl主要区别在于:
wget它的主要优点是它具有递归下载功能。
wget仅命令行,没有lib或任何东西,但是curl的功能由libcurl支持。
curl支持FTP,FTPS,HTTP,HTTPS,SCP,SFTP,TFTP,TELNET,DICT,LDAP,LDAPS,FILE,POP3,IMAP,SMTP,RTMP和RTSP。wget支持HTTP,HTTPS和FTP。
curl可以在比wget。更多的平台上构建和运行。
wget在自由软件copyleft许可证(GNU GPL)下发布,curl根据自由软件许可许可证(MIT衍生产品)发布。
curl提供上传和发送功能,wget仅提供纯HTTP POST支持。
可以在以下链接中查看更多详细信息:curl vs wget
最新版本:2.0
2021年9月下旬,Wget2 2.0 正式发布,该版本是 GNU Wget 的继任者。相比起原来的 GNU Wget,Wget2 更快、支持更多的协议,特别是围绕 HTTP/2 和压缩,支持多线程/并行连接,以及一系列其他的改进。GNU Wget2 2.0 已经历了三年多时间的开发,该版本值得注意的变化包括:
OpenSSL:修复 CRL 检查、实现 ALPN、修复内存泄漏
更新许可证信息
修复可重现的构建问题
增加 Accept-Encoding: lzip
将 --retry-on-http-status 重命名为 --retry-on-http-error
仅限于 leaf pages 的页面要求
修复与 --no-clobber 的目录冲突
使用 --robots=off 下载 robots.txt
增加对 GPGME 的 pkg-config 支持
修复 cookie 文件 header 被 'file' 命令识别的问题
修正在不支持 "系统" 时加载 CA 证书的问题
添加选项 --method,改进向后兼容性
添加选项 --body-data,改进向后兼容性
添加选项 --body-file,改进向后兼容性
添加选项 --ignore-length,改进向后兼容性
添加选项 --convert-file-only,改进向后兼容性
增加选项 --download-attr,利用 HTML5 的 "download" 属性
支持输出中的终端超链接
配置开关 --disable-manylibs 以禁止构建小型库
在 Windows 上支持 --background
增加选项 --bind-interface
增加 HTTP2 上传功能
支持 HTML 下载属性
增加选项 --download-attr=[strippath|usepath] 来控制 download 属性的支持
OpenSSL:增加 OCSP 支持
支持数据:srcset 属性中的 URL
改进了代码、文档、构建、测试、CI ...
更多详情可查看此处。
项目主页:http://www.gnu.org/software/wget/
特点
支持递归下载
恰当的转换页面中的链接
生成可在本地浏览的页面镜像
支持代理服务器
GNU Wget is a free software package for retrieving files using HTTP, HTTPS and FTP, the most widely-used Internet protocols. It is a non-interactive commandline tool, so it may easily be called from scripts, cron jobs, terminals without X-Windows support, etc.
Wget has many features to make retrieving large files or mirroring entire web or FTP sites easy, including:
Can resume aborted downloads, using REST and RANGE
Can use filename wild cards and recursively mirror directories
NLS-based message files for many different languages
Optionally converts absolute links in downloaded documents to relative, so that downloaded documents may link to each other locally
Runs on most UNIX-like operating systems as well as Microsoft Windows
Supports HTTP proxies and cookies
Supports persistent HTTP connections
Unattended / background operation
Uses local file timestamps to determine whether documents need to be re-downloaded when mirroring
wget 非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性。如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕。如果是服务器中断下载过程,它会再次联到服务器上从停止的地方继续下载,这对从那些限定了链接时间的服务器上下载大文件非常有用。它可以跟踪HTML页面上的链接依次下载来创建远程服务器的本地版本,完全重建原始站点的目录结构,常被称作"递归下载"。在递归下载的时候,它遵循Robot Exclusion标准(/robots.txt),它可以在下载的同时,将链接转换成指向本地文件,以方便离线浏览。
wget和curl都支持限制下载速度,手册页中直接提到了这两个选项。
--limit-rate=amount
Limit the download speed to amount bytes per second. Amount may be expressed in bytes, kilobytes with the k suffix, or megabytes with the m suffix. For example, --limit-rate=20k will limit the retrieval rate to 20KB/s. This is useful when, for whatever reason, you don't want Wget to consume the entire available bandwidth.
例如: wget --limit-rate=423k
递归下载网站页面
以下载内核的4.x的最新文档为例(https://www.kernel.org/doc/html/v4.20/)
wget -nd -r -l1 -P /save_location -A jpeg,jpg https://www.kernel.org/doc/html/v4.20/
参数说明:
-nd prevents the creation of a directory hierarchy (i.e. no directories).
-r enables recursive retrieval. See Recursive Download for more information.
-l1 Specify recursion maximum depth level. 1 for just this directory in your case it's products.
-P sets the directory prefix where all files and directories are saved to.
-A sets a whitelist for retrieving only certain file types. Strings and patterns are accepted, and both can be used in a comma separated list (as seen above). See Types of Files for more information.
其它用法1:
wget -nH --page-requisites -R -nH -P mirrorDir https://www.kernel.org/doc/html/v4.20/
wget -r -np -k https://www.kernel.org/doc/html/v4.20/
the useful options:
-nd (no directories): download all files to the current directory
-e robots.off: ignore robots.txt files, don't download robots.txt files
-A png,jpg: accept only files with the extensions png or jpg
-m (mirror): -r --timestamping --level inf --no-remove-listing
-nc, --no-clobber: Skip download if files exist
其它用法2:
wget --execute="robots = off" --mirror --convert-links --no-parent --wait=5 <website-url>
选项解析:
wget: Simple Command to make CURL request and download remote files to our local machine.
--execute="robots = off": This will ignore robots.txt file while crawling through pages. It is helpful if you're not getting all of the files.
--mirror: This option will basically mirror the directory structure for the given URL. It's a shortcut for -N -r -l inf --no-remove-listing which means:
-N: don't re-retrieve files unless newer than local
-r: specify recursive download
-l inf: maximum recursion depth (inf or 0 for infinite)
--no-remove-listing: don't remove '.listing' files
--convert-links: make links in downloaded HTML or CSS point to local files
--no-parent: don't ascend to the parent directory
--wait=5: wait 5 seconds between retrievals. So that we don't thrash the server.
<website-url>: This is the website url from where to download the files.
wget与curl主要区别在于:
wget它的主要优点是它具有递归下载功能。
wget仅命令行,没有lib或任何东西,但是curl的功能由libcurl支持。
curl支持FTP,FTPS,HTTP,HTTPS,SCP,SFTP,TFTP,TELNET,DICT,LDAP,LDAPS,FILE,POP3,IMAP,SMTP,RTMP和RTSP。wget支持HTTP,HTTPS和FTP。
curl可以在比wget。更多的平台上构建和运行。
wget在自由软件copyleft许可证(GNU GPL)下发布,curl根据自由软件许可许可证(MIT衍生产品)发布。
curl提供上传和发送功能,wget仅提供纯HTTP POST支持。
可以在以下链接中查看更多详细信息:curl vs wget
最新版本:2.0
2021年9月下旬,Wget2 2.0 正式发布,该版本是 GNU Wget 的继任者。相比起原来的 GNU Wget,Wget2 更快、支持更多的协议,特别是围绕 HTTP/2 和压缩,支持多线程/并行连接,以及一系列其他的改进。GNU Wget2 2.0 已经历了三年多时间的开发,该版本值得注意的变化包括:
OpenSSL:修复 CRL 检查、实现 ALPN、修复内存泄漏
更新许可证信息
修复可重现的构建问题
增加 Accept-Encoding: lzip
将 --retry-on-http-status 重命名为 --retry-on-http-error
仅限于 leaf pages 的页面要求
修复与 --no-clobber 的目录冲突
使用 --robots=off 下载 robots.txt
增加对 GPGME 的 pkg-config 支持
修复 cookie 文件 header 被 'file' 命令识别的问题
修正在不支持 "系统" 时加载 CA 证书的问题
添加选项 --method,改进向后兼容性
添加选项 --body-data,改进向后兼容性
添加选项 --body-file,改进向后兼容性
添加选项 --ignore-length,改进向后兼容性
添加选项 --convert-file-only,改进向后兼容性
增加选项 --download-attr,利用 HTML5 的 "download" 属性
支持输出中的终端超链接
配置开关 --disable-manylibs 以禁止构建小型库
在 Windows 上支持 --background
增加选项 --bind-interface
增加 HTTP2 上传功能
支持 HTML 下载属性
增加选项 --download-attr=[strippath|usepath] 来控制 download 属性的支持
OpenSSL:增加 OCSP 支持
支持数据:srcset 属性中的 URL
改进了代码、文档、构建、测试、CI ...
更多详情可查看此处。
项目主页:http://www.gnu.org/software/wget/
该文章最后由 阿炯 于 2021-09-29 13:37:29 更新,目前是第 2 版。