跳转至

wget 命令


2014-03-26 by dongnan

举个栗子

保存到标准输出

wget -q -O - http://127.0.0.1/server-status?auto

Total Accesses: 6
Total kBytes: 2
Uptime: 448
ReqPerSec: .0133929
BytesPerSec: 4.57143
BytesPerReq: 341.333
BusyWorkers: 1
IdleWorkers: 7
Scoreboard: ______W_ #...省略

资源重命名

wget -O git.zip https://github.com/git/git/archive/master.zip

指定下载目录

wget -c http://www.internic.net/domain/named.root -P /usr/local/named/master/

限制下载速度

wget -c --limit-rate=500K http://mirrors.163.com/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-bin-DVD1.iso

设置浏览器标识

wget -U "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0" http://ywwd.net/index.html

下载整个网站

wget -U 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)' \
--mirror --convert-links \
--page-requisites \
----no-parent \
-P /tmp/webs http://www.focalbebe.com/

参数

NAME
Wget - The non-interactive network downloader.

SYNOPSIS
wget [option]...
Note that -c only works with FTP servers and with HTTP servers that support the "Range" header.

-q / --quiet
Turn off Wget’s output.

-v / --verbose
Turn on verbose output, with all the available data.  The default output is verbose.

-O file / --output-document=file
The documents will not be written to the appropriate files, 
but all will be concatenated together and written to file.
If - is used as file, documents will be printed to standard output, 
disabling link conversion.  (Use ./- to print to a file literally named -.)

-P prefix / --directory-prefix=prefix 
Set directory prefix to prefix.  
The directory prefix is the  directory where all other files and subdirectories will be saved to, 
i.e. the top of the retrieval tree.  The default is . (the  current directory).

--limit-rate=amount
Limit the download speed to amount bytes per second.  
Amount may be expressed in bytes, kilobytes with the k suffix, or megabytes with the m suffix.  
For example, --limit-rate=20k will limit the retrieval rate to 20KB/s.  
This is useful when, for whatever reason, you don't want Wget to consume the entire available bandwidth.

-U agent-string / --user-agent=agent-string
Identify as agent-string to the HTTP server.
The HTTP protocol allows the clients to identify themselves using a "User-Agent" header field.  
This enables distinguishing the WWW software, usually for statistical purposes or for tracing of protocol violations.  
Wget normally identifies as Wget/version, version being the current version number of Wget.

--mirror 开启镜像所需要的所有选项。
--convert-links 会将所有链接转换成本地链接以便离线浏览。
--page-requisites 表示下载包括CSS样式文件,图片等所有所需的文件,以便离线时能正确地现实页面。
--no-parent 用于限制只下载网站的某一部分内容。
--P 设置下载路径。



回到页面顶部