Linuxcurl是通過url語法在命令行下上傳或下載文件的工具軟件,它支持http,https,ftp,ftps,telnet等多種協議,常被用來抓取網頁和監控Web服務器狀態。
1.linuxcurl抓取網頁:
抓取百度:
curlhttp://www.baidu.com
如發現亂碼,可以使用iconv轉碼:
curlhttp://tech.cxzzl.com.cn/ic.asp|iconv-fgb2312
2.Linuxcurl使用代理:
linuxcurl使用http代理抓取頁面:
linuxcurl使用http代理抓取頁面:
curl-x111.95.243.36:80http://tech.cxzzl.com.cn/ic.asp|iconv-fgb2312curl-x111.95.243.36:80-Uaiezu:passwordhttp://www.baidu.com使用socks代理抓取頁面:
curl--socks4202.113.65.229:443http://tech.cxzzl.com.cn/ic.asp|iconv-fgb2312
curl--socks5202.113.65.229:443http://tech.cxzzl.com.cn/ic.asp|iconv-fgb2312
代理服務器地址可以從看爬蟲代理上獲取。
3.linuxcurl處理cookies
接收cookies:
curl-c/tmp/cookieshttp://www.baidu.com#cookies保存到/tmp/cookies文件
發送cookies:
curl-b"key1=val1;key2=val2;"http://www.baidu.com#發送cookies文本curl-b/tmp/cookieshttp://www.baidu.com#從文件中讀取cookies
4.linuxcurl發送數據:
linuxcurlget方式提交數據:
curl-G-d"name=value&name2=value2"http://www.baidu.com
linuxcurlpost方式提交數據:
curl-d"name=value&name2=value2"http://www.baidu.com#post數據curl-da=b&c=d&txt@/tmp/txthttp://www.baidu.com#post文件以表單的方式上傳文件:
curl-Ffile=@/tmp/me.txthttp://tech.cxzzl.com.cn
相當于設置form表單的method=”POST”和enctype=’multipart/form-data’兩個屬性。
5.linuxcurlhttpheader處理:
設置http請求頭信息:
curl-A"Mozilla/5.0Firefox/21.0"http://www.baidu.com#設置http請求頭User-Agent
curl-e"http://pachong.org/"http://www.baidu.com#設置http請求頭Referer
curl-H"Connection:keep-alive\n
User-Agent:
Mozilla/5.0"
http://tech.cxzzl.com.cn設置http響應頭處理:
curl-Ihttp://tech.cxzzl.com.cn#僅僅返回header
curl-D/tmp/headerhttp://tech.cxzzl.com.cn#將httpheader保存到/tmp/header文件
6.linuxcurl認證:
curl-uaiezu:passwordhttp://tech.cxzzl.com.cn#用戶名密碼認證curl-Emycert.pemhttps://www.baidu.com#采用證書認證
7、其它
curl-#http://www.baidu.com#以“#”號輸出進度條
curl-o/tmp/aiezuhttp://www.baidu.com#保存http響應到/tmp/cxzzl