3

利用wget下载文件和网页

 2 years ago
source link: https://blog.51cto.com/u_12076261/5488107
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

利用wget下载文件和网页

原创

WebCodingTech 2022-07-20 07:38:25 ©著作权

文章标签 html perl wget 文章分类 Linux 系统/运维 阅读数194

wget命令可以下载网页或者远程文件。

[root@localhost ~]# wget https://baidu.com
--2018-05-17 21:28:27-- https://baidu.com/
正在解析主机 baidu.com (baidu.com)... 220.181.57.216, 123.125.115.110
正在连接 baidu.com (baidu.com)|220.181.57.216|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:http://www.baidu.com/ [跟随至新的 URL]
--2018-05-17 21:28:27-- http://www.baidu.com/
正在解析主机 www.baidu.com (www.baidu.com)... 115.239.210.27, 115.239.211.112
正在连接 www.baidu.com (www.baidu.com)|115.239.210.27|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2381 (2.3K) [text/html]
正在保存至: “index.html”
100%[======================================>] 2,381 --.-K/s 用时 0s
2018-05-17 21:28:27 (326 MB/s) - 已保存 “index.html” [2381/2381])

你也可以从多个URL地址进行下载

$ wget url1 url2...

利用选项-O可以指定输出的文件名。

$ wget https://www.baidu.com/img/superlogo_c4d7df0a003d3db9b65e9ef0fe6da1ec.png -O baidu.png

利用选项-t我们可以指定重试的次数,一旦下载中断,wget还会继续尝试。

$ wget -t 5 https://baidu.com

利用--limit-rate选项我们可以限制下载速度

$ wget --limit-rate 100k https://baidu.com

利用-c我们可以进行断点续传

wget有一个极为有用的选项--mirror,顾名思义,这是用来镜像站点的。

$ wget --mirror https://baidu.com

当然,你不能真的完全镜像百度,所以你可以使用--quota或者-Q来限制下载配额。

$ wget -Q 100m https://baidu.com

如果你需要对镜像网站做更精确的控制:

$ wget -r -N -l 5 https://baidu.com

-r是递归选项,-N允许对文件使用时间戳,-l指定遍历的页面级数。

如果你所要下载的网页或者文件需要认证,可以使用--user和--password来提供用户名和密码。

$ wget --user user --password password https://xuyaoyonghuminghemima.com
  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK