日期:2014-05-20  浏览次数:20711 次

java 模拟登录腾讯微博,并获取登录后的页面源码信息!
通过httpclient对腾讯微博实现登录,返回【ptuiCB('0','0','http://t.qq.com','1','登录成功!', '星空璀璨')】,但是获取不到登录成功后的页面源码信息,初次接触这个,不清楚怎么回事,指点一下。谢谢!

只是做了通过HttpGet get = new HttpGet("http://check.ptlogin2.qq.com/check?uin="
+ uin + "&appid=46000101&ptlang=2052&r=" + Math.random())获取验证码;
再对密码进行加密操作;
请求:get = new HttpGet("http://ptlogin2.qq.com/login?ptlang=2052&u="
+ uin
+ "&p="
+ pass
+ "&verifycode="
+ checkNum[1]
+ "&aid=46000101&u1=http%3A%2F%2Ft.qq.com&ptredirect=1&h=1&from_ui=1&dumy=&fp=loginerroralert&action=4-12-14683&g=1&t=1&dummy=")进入登录;
返回【ptuiCB('0','0','http://t.qq.com','1','登录成功!', '星空璀璨')】;成功之后,却获取不了登录成功后的页面源码。
java httpClient 腾讯微博 模拟登录 获取页面源码

------解决方案--------------------
同求。。。。。。。。。
------解决方案--------------------
可以啊,我一直都有做页面抓取,使用登录成功的httpclient实例去访问其他页面就可以了,我这边使用的是httppost登录的,我不知道这个有没有影响。
------解决方案--------------------
楼主问题解决了吗 可以加下QQ 289601537 交流下吗?

------解决方案--------------------


public class HttpClientUtil {

private String userName = "";

private String password = "";

String tmpcookies = "";

private static String redirectURL = "http://i.taobao.com/my_taobao.htm";

private static String loginURL = "https://login.taobao.com/member/login.jhtml";

private HttpResponse response;

private DefaultHttpClient httpclient = null;

private String redirectLocation = null;

private String defaultContent = null;

public HttpClientUtil(String userName, String password) {
this.userName = userName;
this.password = password;
}

public void printInfo(String info){
System.out.println(info);
}

public void printError(String info){
System.out.println(info);
}

@SuppressWarnings("deprecation")
public boolean login() {
printInfo("开始登陆。。。");
if (httpclient != null) {
System.out.println("已经登陆成功");
return true;
}
httpclient = null;
httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(loginURL);
// All the parameters post to the web site
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("origURL", redirectURL));
nvps.add(new BasicNameValuePair("autoLogin", "true"));
nvps.add(new BasicNameValuePair("TPL_username", userName));
nvps.add(new BasicNameValuePair("TPL_password", password));
try {
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
} catch (Exception e) {
printError("登录失败");
e.printStackTrace();
return false;
} finally {
httpost.abort();
}
Header[] hs = response.getAllHeaders();
for (Header h : hs) {
// System.out.println(h.getName() + ":" + h.getValue());
printInfo(h.getName() + ":" + h.getValue());
}
redirectLocation = getRedirectLocation();
redirectLocation = "http://i.taobao.com/my_taobao.htm";
if (getToken() == null) {
System.out.println("登录失败");
return false;
}
List<org.apache.http.cookie.Cookie> cookies = httpclient
.getCookieStore().getCookies();// 取出登陆成功后,服务器返回的cookies信息,里面保存了服务器端给的“临时证”
tmpcookies = "";
for (int i = 0; i < cookies.size(); i++) {
org.apache.http.cookie.Cookie c = cookies.get(i);
tmpcookies = tmpcookies + c.getName() + "=" + c.getValue() + ";";
// System.out.println(c);
}
printInfo("完成登陆");
return true;
}

private String getRedirectLocation() {
Header locationHeader = response.getFirstHeader("Location");