1. 程式人生 > >​瀏覽網頁下載文件命令(十七)

​瀏覽網頁下載文件命令(十七)

background 下載工具 version 後臺運行 日誌記錄

下載工具:wget

瀏覽網頁:curl,elinks,nslookup

13.1.wget

功能:非交互式網絡下載

語法:wget [option]... [URL]...

常用選項:

啟動:

-b, --background 轉入 後臺運行

-V, –version 打印wget版本

-h,help 打印語法幫助

e, –execute=COMMAND 執行`.wgetrc’格式的命令

日誌記錄和輸入文件:

-o, --output-file=FILE 把記錄寫到FILE文件

-a, --append-output=FILE 把記錄追加到FILE文件中

-d, --debug 打印調試輸出,會包含頭信息

-v, –verbose 冗長模式(這是缺省設置)

-nv, –non-verbose 關掉冗長模式,但不是安靜模式

-F, –force-html 把輸入文件當作HTML格式文件對待

-B, –base=URL 將URL作為在-F -i參數指定的文件中出現的相對鏈接的前綴

-q, --quiet 退出

-i, --input-file=FILE 從文件中讀取URL下載

–sslcertfile=FILE 可選客戶端證書

–sslcertkey=KEYFILE 可選客戶端證書的KEYFILE

–egd-file=FILE 指定EGD socket的文件名

下載:

--bind-address=ADDRESS 設置綁定地址(主機名或IP,當本地有多個IP或名字時使用)

-t, --tries=NUMBER 設置鏈接重試次數(0 表示無限制)

-O, --output-document=FILE 把文檔寫到FILE文件中

-nc, --no-clobber 跳過下載現有的文件

-c, --continue 斷點續傳

--progress=TYPE 設置進度條(dot和bar)

-N, –timestamping 不要重新下載文件除非比本地文件新

-S, --server-response 打印服務器響應

--spider 不下載任何內容

-T, --timeout=SECONDS 設置相應超時時間(還有--dns-timeout、--connect-timeout和--read-timeout)

-w, --wait=SECONDS 兩次重試間隔等待時間

–random-wait 在下載之間等待0…2*WAIT秒

-Y, –proxy=on/off 打開或關閉代理

-Q, –quota=NUMBER 設置下載的容量限制

--limit-rate=RATE 限制下載速度

--user=USER 設置ftp和http用戶名

--password=PASS 設置ftp和http密碼

目錄:

-nd –no-directories 不創建目錄

-x, –force-directories 強制創建目錄

-nH, –no-host-directories 不創建主機目錄

-P, --directory-prefix=PREFIX 保存文件目錄

–cut-dirs=NUMBER 忽略 NUMBER層遠程目錄

HTTP選項:

--http-user=USER 設置http用戶名

--http-password=PASS 設置http密碼

-C, –cache=on/off 允許/不允許服務器端的數據緩存 (一般情況下允許)

-E, –html-extension 將所有text/html文檔以.html擴展名保存

–ignore-length 忽略 `Content-Length’頭域

--proxy-user=USER 設置代理用戶名

--proxy-password=PASS 設置代理密碼

--referer=URL 設置Referer

-s,--save-headers 保存頭到文件

--default-page=NAME 改變默認頁面名字,默認index.html

-U,--user-agent=AGENT 設置客戶端信息

--no-http-keep-alive 禁用HTTP keep-alive(長連接)

--load-cookies=FILE 從文件加載cookies

--save-cookies=FILE 保存cookies到文件

--post-data=STRING 使用POST方法,發送數據

FTP選項:

--ftp-user=USER 設置ftp用戶名

--ftp-password=PASS 設置ftp密碼

--no-passive-ftp 禁用被動傳輸模式

-nr, –dont-remove-listing 不移走 `.listing’文件

-g, –glob=on/off 打開或關閉文件名的 globbing機制

–passive-ftp 使用被動傳輸模式 (缺省值).

–active-ftp 使用主動傳輸模式

–retr-symlinks 在遞歸的時候,將鏈接指向文件(而不是目錄)

遞歸下載:

-r, --recursive 指定遞歸下載,慎用!

-l, --level=NUMBER 最大遞歸深度, (inf 或 0 代表無窮).

–delete-after 在現在完畢後局部刪除文件

-k, –convert-links 轉換非相對鏈接為相對鏈接

-K, –backup-converted 在轉換文件X之前,將之備份為 X.orig

-m, –mirror 等價於 -r -N -l inf -nr.

-p, –page-requisites 下載顯示HTML文件的所有圖片


遞歸下載中的包含和不包含(accept/reject)

-A, --accept=LIST 逗號分隔下載的擴展列表

-R, --reject=LIST 逗號分隔不被下載的擴展列表

-D, --domains=LIST 逗號分隔被下載域的列表

--exclude-domains=LIST 排除不被下載域的列表

–follow-ftp 跟蹤HTML文檔中的FTP鏈接

–follow-tags=LIST 分號分隔的被跟蹤的HTML標簽的列表

-G, –ignore-tags=LIST 分號分隔的被忽略的HTML標簽的列表

-H, –span-hosts 當遞歸時轉到外部主機

-L, –relative 僅僅跟蹤相對鏈接

-I, –include-directories=LIST 允許目錄的列表

-X, –exclude-directories=LIST 不被包含目錄的列表

-np, –no-parent 不要追溯到父目錄

示例:

[[email protected] ~]# wget http://nginx.org/download/nginx-1.9.9.tar.gz  #下載單個文件到當前路徑
--2017-06-12 00:02:08--  http://nginx.org/download/nginx-1.9.9.tar.gz
Resolving nginx.org... 206.251.255.63, 95.211.80.227, 2001:1af8:4060:a004:21::e3, ...
Connecting to nginx.org|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 887908 (867K) [application/octet-stream]
Saving to: “nginx-1.9.9.tar.gz”
 
100%[======================================>] 887,908      345K/s   in 2.5s   
 
2017-06-12 00:02:11 (345 KB/s) - “nginx-1.9.9.tar.gz” saved [887908/887908]
# wget -b  http://nginx.org/download/nginx-1.9.9.tar.gz    #放在後臺下載
對於網絡不穩定的用戶使用-c和--tries參數,保證下載完成,並下載到指定目錄:
[[email protected] ~]# wget -t 3 -c http://nginx.org/download/nginx-1.9.9.tar.gz -P down  ##對於網絡不穩或者其他原因,使用-c 和--tries,保證下載完成,並下載到指定的路徑
--2017-06-12 00:06:24--  http://nginx.org/download/nginx-1.9.9.tar.gz
Resolving nginx.org... 95.211.80.227, 206.251.255.63, 2001:1af8:4060:a004:21::e3, ...
Connecting to nginx.org|95.211.80.227|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 887908 (867K) [application/octet-stream]
Saving to: “down/nginx-1.9.9.tar.gz”
 
100%[======================================>] 887,908      364K/s   in 2.4s   
 
2017-06-12 00:06:28 (364 KB/s) - “down/nginx-1.9.9.tar.gz” saved [887908/887908]
[[email protected] scripts]#  wget http://www.baidu.com/index.html -O index.html   #下載內容到文件
--2017-06-12 11:16:23--  http://www.baidu.com/index.html
Resolving www.baidu.com... 14.215.177.38, 14.215.177.37
Connecting to www.baidu.com|14.215.177.38|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: “index.html”
100%[======================================================================================>] 2,381       --.-K/s   in 0s      
2017-06-12 11:16:23 (336 MB/s) - “index.html” saved [2381/2381]
[[email protected] scripts]# ls index.html 
index.html
[[email protected] scripts]# cat > url
https://www.baidu.com/index.html
^C
[[email protected] scripts]# wget -i url   #從文件讀取url下載
--2017-06-12 11:18:48--  https://www.baidu.com/index.html
Resolving www.baidu.com... 14.215.177.38, 14.215.177.37
Connecting to www.baidu.com|14.215.177.38|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2443 (2.4K) [text/html]
Saving to: “index.html.1”
 
100%[======================================================================================>] 2,443       --.-K/s   in 0s     
 
2017-06-12 11:18:49 (11.8 MB/s) - “index.html.1” saved [2443/2443]
 
FINISHED --2017-06-12 11:18:49--
Downloaded: 1 files, 2.4K in 0s (11.8 MB/s)


13.2.curl

功能:傳遞一個url

語法:curl [options] [URL...]

常用選項:

-A/--user-agent <agent string> 指定客戶端信息

-b/--cookie <name=data> 從文件中讀取cookie

-C/--continue-at <offset> 斷點續傳

-c/--cookie-jar <file name> 把cookie保存到文件

-d/--data <data> 使用POST方式發送數據

-D/--dump-header <file> 保存頭信息到文件

--data-urlencode <data> POST的數據URL編碼

-e/--referer <URL> 來源網址

-f/--fail 連接失敗時不顯示http錯誤

-F/--form <name=content> 指定POST數據的表單

--ftp-pasv 指定FTP連接模式PASV/EPSV

-H/--header <header> 自定義頭信息發送給服務器

-L/--location 遵循URL重定向,默認不處理

-I/--head 查看HTTP頭信息


-O/--remote-name 使用遠程服務器上名字寫到本地

-o/--output <file> 輸出到文件

-P/--ftp-port <address> 指定FTP端口

-#/--progress-bar 顯示bar進度條

-x,/--proxy[PROTOCOL://]HOST[:PORT] 使用代理

-U/--proxy-user <user:password> 代理用戶名和密碼

--connect-timeout 連接超時時間,單位秒

--retry NUM 連接重試次數

--retry-delay 兩次重試間隔等待時間

-s/--silent 靜默模式,不輸出任何內容

-Y/--speed-limit 限制下載速率

-u/--user <user:password>指定http和ftp用戶名和密碼

-T/ --upload-file 上傳文件

示例:

[[email protected] scripts]# curl www.baidu.com    #百度字符頁面就展示在命令行上
<!DOCTYPE html>
[[email protected] scripts]# curl -o baidu.html www.baidu.com  #保存頁面
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
103  2381  103  2381    0     0  41981      0 --:--:-- --:--:-- --:--:--  211k
[[email protected] scripts]# ls baidu.html 
baidu.html
[[email protected] scripts]# curl -s -o baidu.html www.baidu.com   #不輸出下載信息
[[email protected] scripts]#
[[email protected] scripts]# curl -b cookies www.baidu.com              #使用cookie訪問
# curl -u user:pass http://www.example.com                              #訪問HTTP認證頁面


13.3.elinks

功能:實現純文本界面訪問網頁

語法:elinks(選項)(參數)

常用選項:

-anonymous:是否使用匿名帳號方式;

-auto-submit:遇到的第一個表單是否自動提交;

-config-dir:指定elinks指令運行時讀取和寫入自身的配置和運行狀態的存放目錄;

-dump:將HTML文檔以純文本的方式打印到標準輸出設備;

-version:打印指令的版本信息;

-h:打印幫助信息。

示例:

[[email protected] ~]# elinks -dump www.baidu.com
   Refresh: [1]/baidu.html?from=noscript
   Link: [2]百度搜索 (search)
   Link: [3]dns-prefetch
   Link: [4]dns-prefetch
   Link: [5]dns-prefetch
   Link: [6]dns-prefetch
   Link: [7]dns-prefetch
   Link: [8]dns-prefetch
   Link: [9]dns-prefetch
   Link: [10]dns-prefetch
   [11]到百度首頁
   [12]_____________________ [13][ 百度一下 ]
   輸入法
 
     * [14]手寫
     * [15]拼音
     * 
     * [16]關閉

13.4.nslookup

功能:交互式查詢Internet名稱服務器,也就是查詢DNS信息

語法:nslookup [-option] [name | -] [server]

示例:

[[email protected] ~]# nslookup
> www.baidu.com
Server:         114.114.114.114    #默認配置dns服務器
Address:        114.114.114.114#53
 
Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com    #對應的百度dns
Address: 163.177.151.110  
Name:   www.a.shifen.com
Address: 163.177.151.109

本文出自 “爛筆頭” 博客,請務必保留此出處http://lanbitou.blog.51cto.com/9921494/1934440

​瀏覽網頁下載文件命令(十七)