您的位置:首页 > 理论基础 > 计算机网络

wget -r -nc -np "http://www.zhihu.com/"

2015-08-11 16:32 555 查看
下载网站所有

-r, --recursive specify recursive download.

-nc, --no-clobber skip downloads that would download to existing files.
-np, --no-parent don’t ascend to the parent directory.

Wget 的使用

1)支持断点下传功能(2)同时支持FTP和HTTP下载方式(3)支持代理服务器(4)设置方便简单;5)程序小,完全免费;

命令格式:

  wget [参数列表] [目标软件、网页的网址]

1、启动类参数

  这一类参数主要提供软件的一些基本信息;

  -V,--version 显示软件版本号然后退出;

  -h,--help显示软件帮助信息;

  -e,--execute=COMMAND 执行一个 “.wgetrc”命令

  以上每一个功能有长短两个参数,长短功能一样,都可以使用。需要注意的是,这里的-e参数是执行一个.wgettrc的命令,.wgettrc命令其实是一个参数列表,直接将软件需要的参数写在一起就可以了。

  2、文件处理参数

  这类参数定义软件log文件的输出方式等;

  -o,--output-file=FILE 将软件输出信息保存到文件;

  -a,--append-output=FILE将软件输出信息追加到文件;

  -d,--debug显示输出信息;

  -q,--quiet 不显示输出信息;

  -i,--input-file=FILE 从文件中取得URL;

  以上参数对于攻击者比较有用,我们来看看具体使用;

例1:下载192.168.1.168首页并且显示下载信息

wget -d http://192.168.1.168
例2:下载192.168.1.168首页并且不显示任何信息

wget -q http://192.168.1.168
例3:下载filelist.txt中所包含的链接的所有文件

wget -i filelist.txt

wget -np -m -l5 http://jpstone.bokee.com
//不下载本站所链接的其它站点内容,5级目录结构

3、下载参数

  下载参数定义下载重复次数、保存文件名等;

  -t,--tries=NUMBER 是否下载次数(0表示无穷次)

  -O --output-document=FILE下载文件保存为别的文件名

  -nc, --no-clobber 不要覆盖已经存在的文件

  -N,--timestamping只下载比本地新的文件

  -T,--timeout=SECONDS 设置超时时间

  -Y,--proxy=on/off 关闭代理

例:下载192.168.1.168的首页并将下载过程中的的输入信息保存到test.htm文件中

wget -o test.htm http://192.168.1.168
4、目录参数

  目录参数主要设置下载文件保存目录与原来文件(服务器文件)的目录对应关系;

  -nd --no-directories 不建立目录

  -x,--force-directories 强制建立目录

  可能现在我们对这里的目录还不是很了解,我们来看一个举例

例:下载192.168.1.168的首页,并且保持网站结构

wget -x http://192.168.1.168
 5、HTTP参数

  HTTP参数设置一些与HTTP下载有关的属性;

  --http-user=USER设置HTTP用户

  --http-passwd=PASS设置HTTP密码

  --proxy-user=USER设置代理用户

  --proxy-passwd=PASS设置代理密码

  以上参数主要设置HTTP和代理的用户、密码;

6、递归参数设置

  在下载一个网站或者网站的一个目录的时候,我们需要知道的下载的层次,这些参数就可以设置;

  -r,--recursive 下载整个网站、目录(小心使用)

  -l,--level=NUMBER 下载层次

例:下载整个网站

wget -r http://192.168.1.168
7、递归允许与拒绝选项参数

  下载一个网站的时候,为了尽量快,有些文件可以选择下载,比如图片和声音,在这里可以设置;

  -A,--accept=LIST 可以接受的文件类型

  -R,--reject=LIST拒绝接受的文件类型

  -D,--domains=LIST可以接受的域名

  --exclude-domains=LIST拒绝的域名

  -L,--relative 下载关联链接

  --follow-ftp 只下载FTP链接

  -H,--span-hosts 可以下载外面的主机

  -I,--include-directories=LIST允许的目录

  -X,--exclude-directories=LIST 拒绝的目录

如何设定wget所使用的代理服务器

wget可以使用用户设置文件".wgetrc"来读取很多设置,我们这里主要利用这个文件来是

设置代理服务器。使用者用什么用户登录,那么什么用户主目录下的".wgetrc"文件就起

作用。例如,"root"用户如果想使用".wgetrc"来设置代理服务器,"/root/.wgetrc"就起

作用,下面给出一个".wgetrc"文件的内容,读者可以参照这个例子来编写自己的"wgetrc"文件:

http-proxy = 111.111.111.111:8080

ftp-proxy = 111.111.111.111:8080

这两行的含义是,代理服务器IP地址为:111.111.111.111,端口号为:80。第一行指定

HTTP协议所使用的代理服务器,第二行指定FTP协议所使用的代理服务器。

WGet使用指南

wget是一个从网络上自动下载文件的自由工具。它支持HTTP,HTTPS和FTP协议,可以使用HTTP代理.

所谓的自动下载是指,wget可以在用户退出系统的之后在后台执行。这意味这你可以登录系统,启动一个wget下载任务,然后退出系统,wget将在后台执行直到任务完成,相对于其它大部分浏览器在下载大量数据时需要用户一直的参与,这省去了极大的麻烦。

wget可以跟踪HTML页面上的链接依次下载来创建远程服务器的本地版本,完全重建原始站点的目录
结构。这又常被称作”递归下载”。在递归下载的时候,wget遵循Robot Exclusion标准(/robots.txt).
wget可以在下载的同时,将链接转换成指向本地文件,以方便离线浏览。

wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性.如果是由于网络的原因下载失
败,wget会不断的尝试,直到整个文件下载完
毕。如果是服务器打断下载过程,它会再次联到服务器上从停止的地方继续下载。这对从那些限定了链接时间的服务器上下载大文件非常有用。

wget的常见用法

wget的使用格式

Usage: wget [OPTION]... [URL]...用wget做站点镜像:

wget -r -p -np -k http://dsec.pku.edu.cn/~usr_name/
# 或者

wget -m http://www.tldp.org/LDP/abs/html/
在不稳定的网络上下载一个部分下载的文件,以及在空闲时段下载

wget -t 0 -w 31 -c http://dsec.pku.edu.cn/BBC.avi
-o down.log &

# 或者从filelist读入要下载的文件列表

wget -t 0 -w 31 -c -B ftp://dsec.pku.edu.cn/linuxsoft
-i filelist.txt -o down.log
&上面的代码还可以用来在网络比较空闲的时段进行下载。我的用法是:在mozilla中将不方便当时下载的URL链接拷贝到内存中然后粘贴到文件
filelist.txt中,在晚上要出去系统前执行上面代码的第二条。

使用代理下载

wget -Y on -p -k https://sourceforge.net/projects/wvware/
代理可以在环境变量或wgetrc文件中设定

# 在环境变量中设定代理

export PROXY=http://211.90.168.94:8080/

# 在~/.wgetrc中设定代理

http_proxy = http://proxy.yoyodyne.com:18023/
ftp_proxy = http://proxy.yoyodyne.com:18023/wget
各种选项分类列表

启动

-V, --version 显示wget的版本后退出

-h, --help 打印语法帮助

-b, --background 启动后转入后台执行

-e, --execute=COMMAND 执行`.wgetrc'格式的命令,wgetrc格式参见/etc/wgetrc或~/.wgetrc记录和输入文件

-o, --output-file=FILE 把记录写到FILE文件中

-a, --append-output=FILE 把记录追加到FILE文件中

-d, --debug 打印调试输出

-q, --quiet 安静模式(没有输出)

-v, --verbose 冗长模式(这是缺省设置)

-nv, --non-verbose 关掉冗长模式,但不是安静模式

-i, --input-file=FILE 下载在FILE文件中出现的URLs

-F, --force-html 把输入文件当作HTML格式文件对待

-B, --base=URL 将URL作为在-F -i参数指定的文件中出现的相对链接的前缀

--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 设定进程条标记

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

-S, --server-response 打印服务器的回应

--spider 不下载任何东西

-T, --timeout=SECONDS 设定响应超时的秒数

-w, --wait=SECONDS 两次尝试之间间隔SECONDS秒

--waitretry=SECONDS 在重新链接之间等待1...SECONDS秒

--random-wait 在下载之间等待0...2*WAIT秒

-Y, --proxy=on/off 打开或关闭代理

-Q, --quota=NUMBER 设置下载的容量限制

--limit-rate=RATE 限定下载输率目录

-nd --no-directories 不创建目录

-x, --force-directories 强制创建目录

-nH, --no-host-directories 不创建主机目录

-P, --directory-prefix=PREFIX 将文件保存到目录 PREFIX/...

--cut-dirs=NUMBER 忽略 NUMBER层远程目录HTTP 选项

--http-user=USER 设定HTTP用户名为 USER.

--http-passwd=PASS 设定http密码为 PASS.

-C, --cache=on/off 允许/不允许服务器端的数据缓存 (一般情况下允许).

-E, --html-extension 将所有text/html文档以.html扩展名保存

--ignore-length 忽略 `Content-Length'头域

--header=STRING 在headers中插入字符串 STRING

--proxy-user=USER 设定代理的用户名为 USER

--proxy-passwd=PASS 设定代理的密码为 PASS

--referer=URL 在HTTP请求中包含 `Referer: URL'头

-s, --save-headers 保存HTTP头到文件

-U, --user-agent=AGENT 设定代理的名称为 AGENT而不是 Wget/VERSION.

--no-http-keep-alive 关闭 HTTP活动链接 (永远链接).

--cookies=off 不使用 cookies.

--load-cookies=FILE 在开始会话前从文件 FILE中加载cookie

--save-cookies=FILE 在会话结束后将 cookies保存到 FILE文件中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 不要追溯到父目录

GNU Wget 1.12, a non-interactive network retriever.
Usage: wget [OPTION]... [URL]...

Mandatory arguments to long options are mandatory for short options too.

Startup:
-V, --version display the version of Wget and exit.
-h, --help print this help.
-b, --background go to background after startup.
-e, --execute=COMMAND execute a ‘.wgetrc’-style command.

Logging and input file:
-o, --output-file=FILE log messages to FILE.
-a, --append-output=FILE append messages to FILE.
-d, --debug print lots of debugging information.
-q, --quiet quiet (no output).
-v, --verbose be verbose (this is the default).
-nv, --no-verbose turn off verboseness, without being quiet.
-i, --input-file=FILE download URLs found in local or external FILE.
-F, --force-html treat input file as HTML.
-B, --base=URL resolves HTML input-file links (-i -F)
relative to URL.

Download:
-t, --tries=NUMBER set number of retries to NUMBER (0 unlimits).
--retry-connrefused retry even if connection is refused.
-O, --output-document=FILE write documents to FILE.
-nc, --no-clobber skip downloads that would download to
existing files.
-c, --continue resume getting a partially-downloaded file.
--progress=TYPE select progress gauge type.
-N, --timestamping don’t re-retrieve files unless newer than
local.
-S, --server-response print server response.
--spider don’t download anything.
-T, --timeout=SECONDS set all timeout values to SECONDS.
--dns-timeout=SECS set the DNS lookup timeout to SECS.
--connect-timeout=SECS set the connect timeout to SECS.
--read-timeout=SECS set the read timeout to SECS.
-w, --wait=SECONDS wait SECONDS between retrievals.
--waitretry=SECONDS wait 1..SECONDS between retries of a retrieval.
--random-wait wait from 0...2*WAIT secs between retrievals.
--no-proxy explicitly turn off proxy.
-Q, --quota=NUMBER set retrieval quota to NUMBER.
--bind-address=ADDRESS bind to ADDRESS (hostname or IP) on local host.
--limit-rate=RATE limit download rate to RATE.
--no-dns-cache disable caching DNS lookups.
--restrict-file-names=OS restrict chars in file names to ones OS allows.
--ignore-case ignore case when matching files/directories.
-4, --inet4-only connect only to IPv4 addresses.
-6, --inet6-only connect only to IPv6 addresses.
--prefer-family=FAMILY connect first to addresses of specified family,
one of IPv6, IPv4, or none.
--user=USER set both ftp and http user to USER.
--password=PASS set both ftp and http password to PASS.
--ask-password prompt for passwords.
--no-iri turn off IRI support.
--local-encoding=ENC use ENC as the local encoding for IRIs.
--remote-encoding=ENC use ENC as the default remote encoding.

Directories:
-nd, --no-directories don’t create directories.
-x, --force-directories force creation of directories.
-nH, --no-host-directories don’t create host directories.
--protocol-directories use protocol name in directories.
-P, --directory-prefix=PREFIX save files to PREFIX/...
--cut-dirs=NUMBER ignore NUMBER remote directory components.

HTTP options:
--http-user=USER set http user to USER.
--http-password=PASS set http password to PASS.
--no-cache disallow server-cached data.
--default-page=NAME Change the default page name (normally
this is ‘index.html’.).
-E, --adjust-extension save HTML/CSS documents with proper extensions.
--ignore-length ignore ‘Content-Length’ header field.
--header=STRING insert STRING among the headers.
--max-redirect maximum redirections allowed per page.
--proxy-user=USER set USER as proxy username.
--proxy-password=PASS set PASS as proxy password.
--referer=URL include ‘Referer: URL’ header in HTTP request.
--save-headers save the HTTP headers to file.
-U, --user-agent=AGENT identify as AGENT instead of Wget/VERSION.
--no-http-keep-alive disable HTTP keep-alive (persistent connections).
--no-cookies don’t use cookies.
--load-cookies=FILE load cookies from FILE before session.
--save-cookies=FILE save cookies to FILE after session.
--keep-session-cookies load and save session (non-permanent) cookies.
--post-data=STRING use the POST method; send STRING as the data.
--post-file=FILE use the POST method; send contents of FILE.
--content-disposition honor the Content-Disposition header when
choosing local file names (EXPERIMENTAL).
--auth-no-challenge send Basic HTTP authentication information
without first waiting for the server’s
challenge.

HTTPS (SSL/TLS) options:
--secure-protocol=PR choose secure protocol, one of auto, SSLv2,
SSLv3, and TLSv1.
--no-check-certificate don’t validate the server’s certificate.
--certificate=FILE client certificate file.
--certificate-type=TYPE client certificate type, PEM or DER.
--private-key=FILE private key file.
--private-key-type=TYPE private key type, PEM or DER.
--ca-certificate=FILE file with the bundle of CA’s.
--ca-directory=DIR directory where hash list of CA’s is stored.
--random-file=FILE file with random data for seeding the SSL PRNG.
--egd-file=FILE file naming the EGD socket with random data.

FTP options:
--ftp-user=USER set ftp user to USER.
--ftp-password=PASS set ftp password to PASS.
--no-remove-listing don’t remove ‘.listing’ files.
--no-glob turn off FTP file name globbing.
--no-passive-ftp disable the “passive” transfer mode.
--retr-symlinks when recursing, get linked-to files (not dir).

Recursive download:
-r, --recursive specify recursive download.
-l, --level=NUMBER maximum recursion depth (inf or 0 for infinite).
--delete-after delete files locally after downloading them.
-k, --convert-links make links in downloaded HTML or CSS point to
local files.
-K, --backup-converted before converting file X, back up as X.orig.
-m, --mirror shortcut for -N -r -l inf --no-remove-listing.
-p, --page-requisites get all images, etc. needed to display HTML page.
--strict-comments turn on strict (SGML) handling of HTML comments.

Recursive accept/reject:
-A, --accept=LIST comma-separated list of accepted extensions.
-R, --reject=LIST comma-separated list of rejected extensions.
-D, --domains=LIST comma-separated list of accepted domains.
--exclude-domains=LIST comma-separated list of rejected domains.
--follow-ftp follow FTP links from HTML documents.
--follow-tags=LIST comma-separated list of followed HTML tags.
--ignore-tags=LIST comma-separated list of ignored HTML tags.
-H, --span-hosts go to foreign hosts when recursive.
-L, --relative follow relative links only.
-I, --include-directories=LIST list of allowed directories.
--trust-server-names use the name specified by the redirection url last component.
-X, --exclude-directories=LIST list of excluded directories.
-np, --no-parent don’t ascend to the parent directory.

Mail bug reports and suggestions to <bug-wget@gnu.org>.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: