Linux curl使用简单介绍(1)


Curl是Linux下一个很强大的http命令行工具,其功能十分强大。

1)读取网页

$ curl linuxboy.net">http://www.linuxboy.net

2)保存网页

$ curl http://www.linuxboy.net > page.html $ curl -o page.html http://www.linuxboy.net

3)使用的proxy服务器及其端口:-x

$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxboy.net

4)使用cookie来记录session信息

$ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxboy.net这个option: -D 是把http的response里面的cookie信息存到一个特别的文件中去,这样,当页面被存到page.html的同时,cookie信息也被存到了cookie0001.txt里面了5)那么,下一次访问的时候,如何继续使用上次留下的cookie信息呢?

使用option来把上次的cookie信息追加到http request里面去:-b

$ curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxboy.net

6)浏览器信息

$ curl -A "Mozilla/4.0 compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxboy.net

7)referer

$ curl -A "Mozilla/4.0 compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.linuxboy.net" -o page.html -D cookie0001.txt http://www.linuxboy.net这样就可以骗对方的服务器,你是从mail.linuxboy.net点击某个链接过来的

8)下载文件

$ curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG $ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG -O 可以按照服务器上的文件名,自动存在本地$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG

9)批量下载

$ curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG这样产生的下载,就是~zzh/001.JPG ~zzh/002.JPG

……

~zzh/201.JPG ~nick/001.JPG ~nick/002.JPG

……

~nick/201.JPG


相关内容