`

(最新)HttpClient4模拟登录腾讯微博

 
阅读更多

        今天在查看网络抓取运行日志时候发现腾讯微博数据获取出现异常,进行跟踪之后发现之前的模拟登陆出现了问题,确切的说是腾讯进行部分代码的调整导致登陆失败。解决思路如下:

1. 查看一下请求地址及参数是否发生变化,如下图:



 

结论:action、login_sig这两个参数导致登陆失败

2. 分析action、login_sig参数的来源



 通过http://jsbeautifier.org/在线格式化工具进行格式化,最终的文件:h_login_11.rar  找到action参数的处理逻辑,仅仅是记录用户键盘行为,不会对登陆有影响,对应就只剩下login_sig这个参数了,但是在h_login_11.js文件中没有发现这个参数,经过分析推测不在js文件中,那就有可能在html中包含的script标签中,经过查看发现如下:


至此,参数确定完毕。

3.基于httpclient 4 来实现参见附件Weibo.rar

核心代码1 写道
/********************* 获取login_sig***********************/
HttpGet preget = new HttpGet("http://ui.ptlogin2.qq.com/cgi-bin/login?appid=46000101&style=13&lang=&low_login=1&hide_title_bar=1&hide_close_icon=1&self_regurl=http%3A//reg.t.qq.com/index.php&s_url=http%3A%2F%2Ft.qq.com&daid=6");
preget.setHeader("Host", "ui.ptlogin2.qq.com");
preget.setHeader("Referer", "http://t.qq.com/?from=11");

HttpResponse response = client.execute(preget);

String entity = EntityUtils.toString(response.getEntity());
String t=entity.substring(entity.indexOf("login_sig:"), entity.indexOf("clientip:"));
String login_sig=t.substring(t.indexOf("\"")+1, t.lastIndexOf("\""));
核心代码2 写道
response = client.execute(get);
entity = EntityUtils.toString(response.getEntity());
/************************* login_sig check ****************************/
String term=entity.split(",")[2];
String url=term.substring(term.indexOf("\'")+1, term.lastIndexOf("\'"));
if (entity.indexOf("登录成功") > -1) {
get = new HttpGet(url);
response = client.execute(get);
entity = EntityUtils.toString(response.getEntity());
}
 

 

 

 

 

 

 

  • 大小: 113.6 KB
  • 大小: 147.7 KB
  • 大小: 137.4 KB
  • 大小: 94.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics