[Mac/Linux] 使用 wget -r 下載整個網站目錄
最近才剛學到用 wget 下載整個網頁目錄的技巧,今天就正好用上了~
同事給我了一個 HTTP 網站的目錄連結,目錄裡有許多的檔案,
要怎麼用 wget 一次將目錄裡的所有檔案都下載下來呢?
答案是使用 wget 的 -r 選項,同時最好是搭配 –no-parent 選項,
避免 wget 不小心往上層目錄去抓,可能會撞到無窮迴圈,或是抓到太大範圍了~
下例中是用 wget 下載 http://1.2.3.4/case 這整個目錄下的檔案:
testuser@localhost ~ $ wget -r --no-parent http://1.2.3.4/case/ --2016-07-07 11:16:37-- http://1.2.3.4/case/ Connecting to 1.2.3.4... connected. HTTP request sent, awaiting response... 401 Unauthorized Authentication selected: Basic realm="Basic Authentication" Reusing existing connection to 1.2.3.4. HTTP request sent, awaiting response... 200 OK Length: 2349 (2.3K) [text/html] Saving to: ‘1.2.3.4/case/index.html’ 2016-07-07 11:16:37 (97.4 MB/s) - ‘1.2.3.4/case/index.html’ saved [2349/2349] --2016-07-07 11:16:37-- http://1.2.3.4/case/Description.txt Reusing existing connection to 1.2.3.4. HTTP request sent, awaiting response... 401 Unauthorized Authentication selected: Basic realm="Basic Authentication" Reusing existing connection to 1.2.3.4. HTTP request sent, awaiting response... 200 OK Length: 774 [text/plain] Saving to: ‘1.2.3.4/case/Description.txt’ 2016-07-07 11:16:37 (92.3 MB/s) - ‘1.2.3.4/case/Description.txt’ saved [774/774] --2016-07-07 11:16:37-- http://1.2.3.4/case/Sample_queue_status.JPG Reusing existing connection to 1.2.3.4. HTTP request sent, awaiting response... 401 Unauthorized Authentication selected: Basic realm="Basic Authentication" Reusing existing connection to 1.2.3.4. HTTP request sent, awaiting response... 200 OK Length: 116226 (114K) [image/jpeg] Saving to: ‘1.2.3.4/case/Sample_queue_status.JPG’
wget 會自動將抓下來的檔案,儲存在 <主機名稱>/<目錄名> 目錄下~
參考資料:Using wget to recursively fetch a directory with arbitrary files in it
(本頁面已被瀏覽過 1,259 次)