CURL -L/--location(登录模拟)

curl -L/--location 参数

这两天模拟浏览器提交登录表单,提交完成后,  The URL has movedhere  。。

每次都需要点击连接后才打开登录后的主页。这并不是我想要的。

又看了一遍说明,看到参数-L

如下:-L/--location      Follow Location: hints (H)
          --location-trusted Follow Location: and send auth to other hosts (H)

有点冲动,感觉这就是问题的关键 :

curl  --output "./rr.html" --dump-header "d_cookie01" --cookie-jar "c_cookie01" --create-dirs  --location --data "email=test&password=test&autoLogin=ture&origURL=&domain=renren.com&formName=&method=&isplogin=true&submit=登录"  http://www.renren.com/PLogin.do

wowowo登录后的主页下载下来了!!

 

仔细查看d_cookie01(包含从c_cookie01的内容,但--cookie-jar 产生的更简洁)有这么一条

Location:http://www.renren.com/callback.do?t=9d5201d04d44156fb070037e9493f5fd3&origURL=http%3A%2F%2Fwww.renren.com%2FHome.do&needNotify=false

原来每次提交登录表单后还需要跳转的,而-L 则是跟随跳转链接的。



我们也可以分成两步去做:

1.先提交表单,保存返回来的cookie

curl  --output "./rr.html" --dump-header "d_cookie01" --data"email=test&password=test&autoLogin=ture&origURL=&domain=renren.com&formName=&method=&isplogin=true&submit=登录"  http://www.renren.com/PLogin.do
2.在d_cookie01中找到location,然后把cookie和location一起提交
curl  --output "./rr.html"  --dump-header "d_cookie01"   --location http://www.renren.com/callback.do?t=9d5201d04d44156fb070037e9493f5fd3&origURL=http%3A%2F%2Fwww.renren.com%2FHome.do&needNotify=false

OK,就拿到了登录后的主页。


115网盘登陆模拟


或是使用FF的firebug工具,具体设置



为了更逼真,我们先访问了下首页,完整模仿实际用户行为
curl -s -A  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -o 1151.html -D 115cookie001.txt http://www.115.com/
找到提交用户信息的post页面(提交用户信息,指定重定向的调转页)
curl -s -A  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -e http://www.115.com/ -o 1152.html -D 115cookie002.txt -b 115cookie001.txt -d back=http://www.115.com -d goto=http://115.com  -d ‘login[account]=$username&login[passwd]=$passwd'  -L 'http://115.com'  'http://passport.115.com/?ac=login'
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值