Linux curl命令参数常用

cURL1 用途

  cURL是一个命令行方式下传输数据的开源传输工具。常被用来抓取网页和监控Web服务器状态。

2 支持协议

  DICT, FILE, FTP, FTPS,GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET 和 TFTP。

3 描述

  Thecommand is designed to work without user interaction.

  The URL syntax is protocol-dependent. You’ll find a detailed description in RFC 3986.

  curl normally displays a progress meter during operations, indicating the amount of transferred data, transfer speedsand estimated time left, etc.

curl displays this data to the terminal by default, so if you invoke curl to do an operation and it is about to writedata to the terminal, it disables the progress meter as otherwise it would mess up the output mixing progress meter andresponse data.

4 用法

1. linux curl抓取网页:

抓取百度:

1curl http://www.baidu.com

如发现乱码,可以使用iconv转码:

1curlhttp://iframe.ip138.com/ic.asp|iconv -fgb2312

iconv的用法请参阅:在Linux/Unix系统下用iconv命令处理文本文件中文乱码问题

2. Linux curl使用代理:

linux curl使用http代理抓取页面:

12curl-x111.95.243.36:80http://iframe.ip138.com/ic.asp|iconv -fgb2312curl-x111.95.243.36:80-Uaiezu:password http://www.baidu.com

使用socks代理抓取页面:

12curl–socks4202.113.65.229:443http://iframe.ip138.com/ic.asp|iconv -fgb2312curl–socks5202.113.65.229:443http://iframe.ip138.com/ic.asp|iconv -fgb2312

代理服务器地址可以从爬虫代理上获取。

3. linux curl处理cookies

接收cookies:

1curl-c/tmp/cookies http://www.baidu.com #cookies保存到/tmp/cookies文件

发送cookies:

12curl-b"key1=val1;key2=val2;"http://www.baidu.com #发送cookies文本curl-b/tmp/cookieshttp://www.baidu.com #从文件中读取cookies

4. linux curl发送数据:

linux curlget方式提交数据:

1curl-G-d"name=value&name2=value2"http://www.baidu.com

linux curlpost方式提交数据:

12curl-d"name=value&name2=value2"http://www.baidu.com #post数据curl-da=b&c=d&txt@/tmp/txthttp://www.baidu.com#post文件

以表单的方式上传文件:

1curl-Ffile=@/tmp/me.txt http://www.aiezu.com

相当于设置form表单的method="POST"和enctype=’multipart/form-data’两个属性。

5. linux curl http header处理:

设置http请求头信息:

123curl-A"Mozilla/5.0 Firefox/21.0"http://www.baidu.com #设置http请求头User-Agentcurl-e"http://pachong.org/"http://www.baidu.com #设置http请求头Referercurl-H"Connection:keep-alive \n User-Agent: Mozilla/5.0"http://www.aiezu.com

设置http响应头处理:

12curl-Ihttp://www.aiezu.com #仅仅返回headercurl-D/tmp/header http://www.aiezu.com #将http header保存到/tmp/header文件

6. linux curl认证:

12curl-uaiezu:passwordhttp://www.aiezu.com #用户名密码认证curl-Emycert.pemhttps://www.baidu.com #采用证书认证

7. 其他:

12curl-# http://www.baidu.com #以“#”号输出进度条curl-o/tmp/aiezuhttp://www.baidu.com #保存http响应到/tmp/aiezu

ubuntu server环境安装virtualbox增强工具 iperf 主题推荐 linux curl web服务器 代理服务器 数据 猜你在找 ‘ }); 查看评论 * 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场 核心技术类目 全部主题HadoopAWS移动游戏JavaAndroidiOSSwift智能硬件DockerOpenStackVPNSparkERPIE10EclipseCRMJavaScript数据库UbuntuNFCWAPjQueryBIHTML5SpringApache.NETAPIHTMLSDKIISFedoraXMLLBSUnitySplashtopUMLcomponentsWindows MobileRailsQEMUKDECassandraCloudStackFTCcoremailOPhone CouchBase云计算iOS6Rackspace Web AppSpringSideMaemoCompuware大数据aptechPerlTornadoRubyHibernateThinkPHPHBasePureSolrAngularCloud FoundryRedisScalaDjangoBootstrap ‘); $(‘#popup_mask’).css({ opacity: 0.5, width: $( document ).width() + ‘px’, height: $( document ).height() + ‘px’ }); $(‘#popup_mask’).css(“display”,”block”); $logpop.css( { top: ($( window ).height() – $logpop.height())/ 2 + $( window ).scrollTop() + ‘px’, left:($( window ).width() – $logpop.width())/ 2 } ); setTimeout( function () { $logpop.show(); $logpop.css( { opacity: 1 } ); }, 200 ); $(‘#popup_mask’).unbind(“click”); $(‘#popup_mask’).bind(“click”, function(){ $(‘#popup_mask’).hide(); var $clopop = $(“#pop_win”); $(“#common_ask_div_sc”).css(“display”,”none”); $clopop.css( { opacity: 0 } ); setTimeout( function () { $clopop.hide(); }, 350 ); return false; }); } 获致幸福的不二法门是珍视你所拥有的、遗忘你所没有的

Linux curl命令参数常用

相关文章:

你感兴趣的文章:

标签云: