Curl是Linux下一個很強大的http命令列工具,其功能十分強大。
1)讀取網頁
$ curl linuxidc.com">http://www.linuxidc.com
2)儲存網頁
$ curl http://www.linuxidc.com > page.html $ curl -o page.html http://www.linuxidc.com
3)使用的proxy伺服器及其連接埠:-x
$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com
4)使用cookie來記錄session資訊
$ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com這個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.linuxidc.com
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.linuxidc.com
7)referer
$ curl -A "Mozilla/4.0 compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.linuxidc.com" -o page.html -D cookie0001.txt http://www.linuxidc.com這樣就可以騙對方的伺服器,你是從mail.linuxidc.com點擊某個連結過來的
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