用wget递归下载

[备忘]:Linux命令行下常用的http下载工具有wget和curl。

1. 这里用wget递归下载某目录下所有除html外的文件~

wget -r -np --reject=html www.download.example

其中:

-r, 表示递归下载当前页面所有(子)链接

-np,表示不去遍历父目录下内容

--reject=html,不接受扩展名为html的文件

或者可以把reject换做 --accept=iso,c,h,表示只接受以此结尾的文件,分隔符为逗号(comma-separated)

 

2. 用curl来查看http过程

curl -v here.is.your.url

我用该选项查看取服务器上主页的过程,主要是这里包括了http header:

zxluo@polaris:~$ curl -v 192.168.1.1
* About to connect() to 192.168.1.1 port 80 (#0)
*   Trying 192.168.1.1... connected
* Connected to 192.168.1.1 (192.168.1.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6
> Host: 192.168.1.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Tue, 26 Feb 2013 07:52:54 GMT
< Server: Apache/2.2.16 (Debian)
< Last-Modified: Wed, 18 Apr 2012 12:18:11 GMT
< ETag: "a002-b1-4bdf30c7c06c0"
< Accept-Ranges: bytes
< Content-Length: 177
< Vary: Accept-Encoding
< Content-Type: text/html
< 
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
* Connection #0 to host 192.168.1.1 left intact
* Closing connection #0

 另外,curl -i here.is.your.url只显示response的头信息。

 

3. 表单提交

发送表单信息有GET和POST两种方法。GET方法相对简单,只要把数据附在网址后面就行。

curl example.com/form.cgi?data=xxx

  POST方法必须把数据和网址分开,curl就要用到--data参数。

curl --data "data=xxx" example.com/form.cgi

  如果你的数据没有经过表单编码,还可以让curl为你编码,参数是--data-urlencode。

curl --data-urlencode "date=April 1" example.com/form.cgi

 你可以用curl这样上传文件:

curl --form upload=@localfilename --form press=OK [URL]

 

4. HTTP认证

有些网域需要HTTP认证,这时curl需要用到--user参数。

curl --user name:password example.com

  

参考资料:教你学用curl

posted @ 2013-01-30 15:23  Biiigfish  阅读(8962)  评论(0编辑  收藏  举报