Wget下載終極用法和15個詳細的例子
Wget是一種很好用的因特網下載工具,他具備的不少特性是其餘工具所不能比擬的,再者他是一個輕量級可配置的下載工具。
本文結合例子介紹Windows下wget的多種下載方法和用途。
一、用Wget下載單個文件
下載的時候會顯示:
~文件的大小、鏈接狀態、鏈接地址以及文件的大小
~保存的名稱
~下載進度條
~下載速度、時間,還有多少未下載
例如我下載editplus時輸入
D:\Hack stuff\wget>wget http://software-files-a.cnet.com/s/software/12/32/81/47/epp331.exe?token=1329413178_4553efa847829f3ecef10c1bc256fcc0&lop=link&ptype=3001&ontid=2352&siteId=4&edId=3&spi=537d5d5485f688682d82c481c4fb15a1&pid=12328147&psid=10018241&&fileName=epp331.exe則下載時會顯示如下內容
D:\Hack stuff\wget>wget http://software-files-a.cnet.com/s/software/12/32/81/47/epp331.exe?token=1329413178_4553efa847829f3ecef10c1bc256fcc0&lop=link&ptype=3001&ontid=2352&siteId=4&edId=3&spi=537d5d5485f688682d82c481c4fb15a1&pid=12328147&psid=10018241&&fileName=epp331.exe--2012-02-16 15:28:50-- http://software-files-a.cnet.com/s/software/12/32/81/47/epp331.exe?token=1329413178_4553efa847829f3ecef10c1bc256fcc0Resolving software-files-a.cnet.com... 204.2.171.33, 204.2.171.35Connecting to software-files-a.cnet.com|204.2.171.33|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 1766464 (1.7M) [application/octet-stream]Saving to: `epp331.exe@token=1329413178_4553efa847829f3ecef10c1bc256fcc0'18% [======> ] 335,238 20.5K/s eta 64s
二、用Wget-O下載能夠爲下載的文件指定另一個名字
默認狀況下wget會用最後的斜線後面的全部字符來命名下載下來的文件,如上例所示保存的文件名爲
Saving to: `epp331.exe@token=1329413178_4553efa847829f3ecef10c1bc256fcc0'這不是咱們所想要的,咱們能夠用-O選項來改變將文件保存爲editplus.exe
D:\Hack stuff\wget>wget -O editplus.exe http://software-files-a.cnet.com/s/software/12/32/81/47/epp331.exe?token=1329413178_4553efa847829f3ecef10c1bc256fcc0&lop=link&ptype=3001&ontid=2352&siteId=4&edId=3&spi=537d5d5485f688682d82c481c4fb15a1&pid=12328147&psid=10018241&&fileName=epp331.exe
三、用Wget --limit-rate指定下載的速度
以下面這個例子限制速度爲300k
D:\Hack stuff\wget>wget --limit-rate=300k http://downloads.sourceforge.net/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2F&ts=1329379231&use_mirror=nchc
四、續傳下載用Wget -c
當你在下載一個大文件時忽然中斷了那麼這個選項就派上用場了
D:\Hack stuff\wget>wget -c http://downloads.sourceforge.net/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2F&ts=1329379231&use_mirror=nchc
五、後臺下載用wget -b
用此選項下載時只會初始化下載而不會顯示相關信息
D:\Hack stuff\wget>wget -b http://downloads.sourceforge.net/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2F&ts=1329379231&use_mirror=nchcContinuing in background, pid 6132.Output will be written to `wget-log'.
下載之後會在wget目錄下生產wget-log文件,用記事本打開可查看裏面的內容以下所示
--2012-02-16 16:12:55-- http://downloads.sourceforge.net/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2FResolving downloads.sourceforge.net... 216.34.181.59Connecting to downloads.sourceforge.net|216.34.181.59|:80... connected.HTTP request sent, awaiting response... 302 FoundLocation: http://nchc.dl.sourceforge.net/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zip [following]--2012-02-16 16:12:56-- http://nchc.dl.sourceforge.net/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zipResolving nchc.dl.sourceforge.net... 211.79.60.17Connecting to nchc.dl.sourceforge.net|211.79.60.17|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 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
六、測試你要下載的地址用Wget --spider
wget --spider DOWNLOAD-URL若是所給URL是正確的則會顯示
Resolving downloads.sourceforge.net... 216.34.181.59Connecting to downloads.sourceforge.net|216.34.181.59|:80... connected.HTTP request sent, awaiting response... 302 FoundLocation: http://ncu.dl.sourceforge.net/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zip [following]Spider mode enabled. Check if remote file exists.--2012-02-16 16:21:08-- http://ncu.dl.sourceforge.net/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zipResolving ncu.dl.sourceforge.net... 140.115.17.45Connecting to ncu.dl.sourceforge.net|140.115.17.45|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 31421410 (30M) [application/zip]Remote file exists.
不然顯示
Spider mode enabled. Check if remote file exists.--2012-02-16 16:23:06-- http://downloads.sourceforge.net/project/boost/boost-docs/1.47.0/boost_1_47_pdf222.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2FResolving downloads.sourceforge.net... 216.34.181.59Connecting to downloads.sourceforge.net|216.34.181.59|:80... connected.HTTP request sent, awaiting response... 404 Not FoundRemote file does not exist -- broken link!!!
七、增長重連次數用Wget -tries
在網絡有問題的狀況次選項尤爲有用,默認是wget會重連20次以成功完成下載,咱們能夠把他增長爲咱們期待的次數
wget --tries=100 DOWNLOAD-URL
八、下載多個文件/URLS用wget -i
首先把全部要下載的文件或者URL存到一個記事本中,好比aa.txt,裏面內容以下
URL1URL2URL3URL4接下來輸入以下代碼就能夠批量下載了
wget -i aa.txt
九、下載一個完整的網站用wget -mirror
如下實現是你想完整的下載一個網站用於本地瀏覽
wget --mirror -p --convert-links -P LOCAL-DIR WEBSITE-URL--mirror:打開鏡像選項
-p:下載全部用於顯示給定網址所必須的文件
--convert-links:下載之後,轉換連接用於本地顯示
-P LOCAL_DIR:保存全部的文件或目錄到指定的目錄下
十、保存輸出到日誌文件而不是標準輸出用wget -o
當你想要把信息保存到一個文件而不是在終端顯示時用如下代碼。
wget -o download.log DOWNLOAD-URL
十一、當超過指定大小時終止下載用wget -Q
當文件已下載10M,此時你想中止下載可使用下面的命令行
wget -Q10m -i FILE-WHICH-HAS-URLS注意:此選項只能在下載多個文件時有用,當你下載一個文件時沒用。
十二、下載特定文件類型的文件用wget -r -A
你能夠用此方法下載一下文件:
~從一個網站下載全部圖片
~從一個網站下載全部視頻
~從一個網站下載全部PDF文件
wget -r -A.pdf http://url-to-webpage-with-pdfs/
1三、指定不下載某一類型的文件用wget --reject
你發現一個網站頗有用,可是你不想下載上面的圖片,由於太佔流量,此時你能夠用以下命令。
wget --reject=gif WEBSITE-TO-BE-DOWNLOADED
1四、用wget實現FTP下載
匿名FTP下載用
wget ftp-url有用戶名和密碼的FTP下載
wget --ftp-user=USERNAME --ftp-password=PASSWORD DOWNLOAD-URL
1五、wget下載有的資源時必須用選項 --no-check-certificate,不然會提示沒有認證不容許下載
wget --no-check-certificate URLweb