wget下载终极⽤法和15个详细的例⼦
Wget是⼀种很好⽤的因特⽹下载⼯具,他具有的很多特性是其他⼯具所不能⽐拟的,再者他是⼀个轻量级可配置的下载⼯具。本⽂结合例⼦介绍Windows下wget的多种下载⽅法和⽤途。
1、⽤Wget下载单个⽂件
下载的时候会显⽰:
  ~⽂件的⼤⼩、连接状态、连接地址以及⽂件的⼤⼩
  ~保存的名称
  ~下载进度条
  ~下载速度、时间,还有多少未下载
例如我下载editplus时输⼊
D:\Hack stuff\wget>wget software-files-aet/s/software/12/32/81/47/
<?token=1329413178_4553efa847829f3ecef10c1bc256fcc0&lop=link&ptype=3001
&ontid=2352&siteId=4&edId=3&spi=537d5d5485f688682d82c481c4fb15a1&pid=12328147&ps
id=10018241&&
则下载时会显⽰以下内容
D:\Hack stuff\wget>wget software-files-aet/s/software/12/32/81/47/
<?token=1329413178_4553efa847829f3ecef10c1bc256fcc0&lop=link&ptype=3001
&ontid=2352&siteId=4&edId=3&spi=537d5d5485f688682d82c481c4fb15a1&pid=12328147&ps
id=10018241&&
--2012-02-16 15:28:50--  software-files-aet/s/software/12/32/81/47
/?token=1329413178_4553efa847829f3ecef10c1bc256fcc0
204.2.171.33, 204.2.171.35
Connecting to software-files-aet|204.2.171.33|:80... connected.
HTTP request sent, 200 OK
Length: 1766464 (1.7M) [application/octet-stream]
Saving to: `@token=1329413178_4553efa847829f3ecef10c1bc256fcc0'
18% [======>                                ] 335,238    20.5K/s  eta 64s
2、⽤Wget-O下载可以为下载的⽂件指定另外⼀个名字
默认情况下wget会⽤最后的斜线后⾯的所有字符来命名下载下来的⽂件,如上例所⽰保存的⽂件名为Saving to: `@token=1329413178_4553efa847829f3ecef10c1bc256fcc0'
这不是我们所想要的,我们可以⽤-O选项来改变将⽂件保存为
D:\Hack stuff\wget>wget - software-files-aet/s/software/12/32/81/47/
<?token=1329413178_4553efa847829f3ecef10c1bc256fcc0&lop=link&ptype=3001
&ontid=2352&siteId=4&edId=3&spi=537d5d5485f688682d82c481c4fb15a1&pid=12328147&ps
id=10018241&&
3、⽤Wget --limit-rate指定下载的速度
如下⾯这个例⼦限制速度为300k
D:\Hack stuff\wget>wget --limit-rate=300k downloads.sourceforge/project/boost/boost-doc
s/1.47.0/boost_1_47_pdf.zip?r=http%3A%2F%2Fsourceforge%2Fprojects%2Fboost%2F
&ts=1329379231&use_mirror=nchc
4、续传下载⽤Wget -c
当你在下载⼀个⼤⽂件时突然中断了那么这个选项就派上⽤场了
D:\Hack stuff\wget>wget -c downloads.sourceforge/project/boost/boost-doc
s/1.47.0/boost_1_47_pdf.zip?r=http%3A%2F%2Fsourceforge%2Fprojects%2Fboost%2F
&ts=1329379231&use_mirror=nchc
5、后台下载⽤wget -b
⽤此选项下载时只会初始化下载⽽不会显⽰相关信息
D:\Hack stuff\wget>wget -b downloads.sourceforge/project/boost/boost-
docs/1.47.0/boost_1_47_pdf.zip?r=http%3A%2F%2Fsourceforge%2Fprojects%2Fboost
%2F&ts=1329379231&use_mirror=nchc
Continuing in background, pid 6132.
Output will be written to `wget-log'.
下载以后会在wget⽬录下⽣产wget-log⽂件,⽤记事本打开可查看⾥⾯的内容如下所⽰
--2012-02-16 16:12:55--  downloads.sourceforge/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zip?r=http%3A%2F%2Fsourceforge%2 Resolving 216.34.181.59
Connecting to downloads.sourceforge|216.34.181.59|:80... connected.
HTTP request sent, 302 Found
Location: nchc.dl.sourceforge/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zip [following]
--2012-02-16 16:12:56--  nchc.dl.sourceforge/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zip
Resolving nchc. 211.79.60.17
Connecting to nchc.dl.sourceforge|211.79.60.17|:80... connected.
HTTP request sent, 200 OK
Length: 31421410 (30M) [application/zip]
Saving to: `boost_1_47_pdf.zip.4'
0K .......... .......... .......... .......... ..........  0% 19.7K 25m51s
50K .......... .......... .......... .......... ..........  0% 29.1K 21m40s
100K .......... .......... .......... .......... ..........  0% 20.8K 22m35s
150K .......... .......... .......... .......... ..........  0% 19.5K 23m26s
200K .......... .......... .......... .......... ..........  0% 18.4K 24m13s
250K .......... .......... .......... .......... ..........  0% 20.8K 24m13s
300K .......... .......... .......... .......... ..........  1% 18.2K 24m41s
350K .......... .......... .......... .......... ..........  1% 23.5K 24m16s
6、你要下载的地址⽤Wget --spider
wget --spider DOWNLOAD-URL
如果所给URL是正确的则会显⽰
Resolving 216.34.181.59
Connecting to downloads.sourceforge|216.34.181.59|:80... connected.
HTTP request sent, 302 Found
Location: ncu.dl.sourceforge/project/boost/boost-docs/1.47.0/boost_1_
47_pdf.zip [following]exists的用法
Spider mode enabled. Check if remote file exists.
--2012-02-16 16:21:08--  ncu.dl.sourceforge/project/boost/boost-docs/
1.47.0/boost_1_47_pdf.zip
Resolving ncu. 140.115.17.45
Connecting to ncu.dl.sourceforge|140.115.17.45|:80... connected.
HTTP request sent, 200 OK
Length: 31421410 (30M) [application/zip]
Remote file exists.
否则显⽰
Spider mode enabled. Check if remote file exists.
--2012-02-16 16:23:06--  downloads.sourceforge/project/boost/boost-do
cs/1.47.0/boost_1_47_pdf222.zip?r=http%3A%2F%2Fsourceforge%2Fprojects%2Fboos
t%2F
Resolving 216.34.181.59
Connecting to downloads.sourceforge|216.34.181.59|:80... connected.
HTTP request sent, 404 Not Found
Remote file does not exist -- broken link
7、增加重连次数⽤Wget -tries
在⽹络有问题的情况次选项尤其有⽤,默认是wget会重连20次以成功完成下载,我们可以把他增加为我们期待的次数wget --tries=100 DOWNLOAD-URL
8、下载多个⽂件/URLS⽤wget -i
⾸先把所有要下载的⽂件或者URL存到⼀个记事本中,⽐如aa.txt,⾥⾯内容如下
URL1
URL2
URL3
URL4
接下来输⼊如下代码就可以批量下载了
wget -
9、下载⼀个完整的⽹站⽤wget -mirror
以下实现是你想完整的下载⼀个⽹站⽤于本地浏览
wget --mirror  -p --convert-links -P LOCAL-DIR WEBSITE-URL
--mirror:打开镜像选项
-
p:下载所有⽤于显⽰给定⽹址所必须的⽂件
--convert-links:下载以后,转换链接⽤于本地显⽰
-P LOCAL_DIR:保存所有的⽂件或⽬录到指定的⽬录下
10、保存输出到⽇志⽂件⽽不是标准输出⽤wget -o
当你想要把信息保存到⼀个⽂件⽽不是在终端显⽰时⽤以下代码。
wget -o download.log DOWNLOAD-URL
11、当超过指定⼤⼩时终⽌下载⽤wget -Q
当⽂件已下载10M,此时你想停⽌下载可以使⽤下⾯的命令⾏
wget -Q10m -i FILE-WHICH-HAS-URLS
注意:此选项只能在下载多个⽂件时有⽤,当你下载⼀个⽂件时没⽤。
12、下载特定⽂件类型的⽂件⽤wget -r -A
你可以⽤此⽅法下载⼀下⽂件:
~从⼀个⽹站下载所有图⽚
~从⼀个⽹站下载所有视频
~从⼀个⽹站下载所有PDF⽂件
wget -r -A.pdf url-to-webpage-with-pdfs/
13、指定不下载某⼀类型的⽂件⽤wget --reject
你发现⼀个⽹站很有⽤,但是你不想下载上⾯的图⽚,因为太占流量,此时你可以⽤如下命令。
wget --reject=gif WEBSITE-TO-BE-DOWNLOADED
14、⽤wget实现FTP下载
匿名FTP下载⽤
wget ftp-url
有⽤户名和密码的FTP下载
wget --ftp-user=USERNAME --ftp-password=PASSWORD DOWNLOAD-URL
15、wget下载有的资源时必须⽤选项 --no-check-certificate,否则会提⽰没有认证不允许下载
wget --no-check-certificate URL

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。