curl使用笔记

来源:互联网 发布:斗地主软件下载 编辑:程序博客网 时间:2024/06/05 03:01
curl
显示返回的头信息
 -I/--head          Show document info only

如果遇到了一个多次跳转的URL,可以先用curl的 -L 参数看看,这个URL最终跳转到了什么地方
 -L/--location      Follow Location: hints (H)
    --location-trusted Follow Location: and send auth to other hosts (H)

-L 参数最好配合 -I 使用,不然cURL会把最后一次请求获得的数据输出到控制台。

curl -L -I http://www.flickr.com/services/auth/?api_key=414b612d9e45cea5164dccb6a26ac861&perms=write&frob=72157630007720051-32e737f131739e3b-968122&api_sig=d4488582bdf975f3f1b57ce47d89c8fd

会输出两个location
...
location: http://www.flickr.com/signin/?acf=%2Fservices%2Fauth%2F%3Fapi_key%3D414b612d9e45cea5164dccb6a26ac861
....
location: https://login.yahoo.com/config/login?.src=flickrsignin&.pc=8190&.scrumb=0&.pd=c%3DJvVF95K62e6PzdPu7MBv2V8-&.intl=us&.done=https%3A%2F%2Flogin.yahoo.com%2Fconfig%2Fvalidate%3F.src%3Dflickrsignin%26.pc%3D8190%26.scrumb%3D0%26.pd%3Dc%253DJvVF95K62e6PzdPu7MBv2V8-%26.intl%3Dus%26.done%3Dhttp%253A%252F%252Fwww.flickr.com%252Fsignin%252Fyahoo%252F%253Fredir%253D%25252Fservices%25252Fauth%25252F%25253Fapi_key%25253D414b612d9e45cea5164dccb6a26ac861
....
其它信息略

接下来说说用curl如何判断登录某个网站成功
用正确的用户名与密码登录一次,再用错误的用户名或密码登录一次,两次分别把输出重定向到不同文件中
然后再用比较文本的软件比较这两个文件,就可以得到二者的不同之处,正是这个不同之处区分了是否登录成功,
这样你下次登录时就可以以此判断登录状态
下面以yahoo的登录为例
curl -Ld "login=user@yahoo.com&passwd=pass" "https://login.yahoo.com/config/login" > log
用户密码都正确的情况(登录也失败了,cookies不对)
<div class="yregertxt"><strong>The browser you're using refuses to sign in. (cookies rejected)</strong>
用户不正确的情况



  1. <div class="yregertxt"><strong><strong>This ID is not yet taken.</strong><br>Are you trying to <a href="https://edit.yahoo.com/config/eval_register?login=tczenging&.intl=us&.lang=en&.done=http%3A//my.yahoo.com&.src=&.v=0&.u=0ha8o9d7t622c&partner=&.p=&promo=&.last=&.testid=sprads_tst"> register</a> for a new account?</strong>
这样可以通过查找<div class="yregertxt"><strong>里的值来判断登录状态
作者:帅得不敢出门 程序员群:31843264
0 0
原创粉丝点击