curl 网页抓取

如果要把这个网页保存下来,可以使用-o参数,这就相当于使用wget命令了。

  curl -o [文件名] www.tvbs.cc

二、自动跳转

有的网址是自动跳转的。使用-L参数,curl就会跳转到新的网址。

  curl -L www.tvbs.cc

键入上面的命令,结果就自动跳转为www.tvbs.cc。

curl -u username:pass http://www.xxx.com

需要传递用户名密码校验的请求

Windows 登录验证的还需要使用

curl --ntlm -u username:paassword 格式



curl -H "Authorization token:xxxxxx"  http://www.xxx.com

需要传递token校验的请求

curl -H "ContentType: text" --request GETDELETEPUT http://www.xxxx.com

需要指定http method的请求

curl -I http://www.xxx.com

只获取header信息

curl -H ""Content-Type: application/json"  -d '{"name":"name"}--request GETDELETEPUT http://www.xxxx.com

提交数据json格式

curl -H ""Content-Type: application/json"  -d 'a=1&b=2' --request GETDELETEPUT http://www.xxxx.com

 

$curl -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} http://www.xxx.com

0.081:0.272:0.779

使用 cURL 度量 Web 站点的响应时间

通过 -o 参数发送到 /dev/null。 -s 参数去掉所有状态信息。-w参数让 curl 写出列出的计时器的状态信息:

time_connect     建立到服务器的 TCP 连接所用的时间
time_starttransfer     在发出请求之后,Web 服务器返回数据的第一个字节所用的时间
time_total         完成请求所用的时间

原文地址:https://www.cnblogs.com/micro-chen/p/4977800.html