3g人人后台java登陆(httpclient4.4+jsoup)-初版
来源:互联网 发布:穆雅斓的淘宝店没有了 编辑:程序博客网 时间:2024/06/14 22:18
package com.chenjazz.testMobilRenren;import java.io.IOException;import java.util.ArrayList;import java.util.List;import org.apache.http.Header;import org.apache.http.HttpEntity;import org.apache.http.NameValuePair;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.CloseableHttpResponse;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClients;import org.apache.http.message.BasicNameValuePair;import org.apache.http.util.EntityUtils;import org.jsoup.Jsoup;import org.jsoup.nodes.Document;import org.jsoup.select.Elements;/** * @ClassName: Test * @Description: * @author chenjazz@foxmail.com * @date 2015年6月8日 上午9:55:02 */public class Test {public static void main(String[] args) throws ClientProtocolException, IOException, InterruptedException {CloseableHttpClient httpclient = HttpClients.createDefault();String email="你的人人email账号";String password="你的密码";try {// 1.到登陆界面--wap.renren.comSystem.err.println("步骤1:登陆http://wap.renren.com,获取lbskey...");HttpGet httpGet1 = new HttpGet("http://wap.renren.com");httpGet1.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3");CloseableHttpResponse response1 = httpclient.execute(httpGet1);HttpEntity entity1 = response1.getEntity();// 得到响应正文// Jsoup的用法:详见http://www.open-open.com/jsoup/Document doc1 = Jsoup.parse(EntityUtils.toString(entity1));Elements el1 = doc1.select("input[name=lbskey]");String key = el1.attr("value").toString();System.out.println(" "+el1.attr("value").toString());// 释放实体EntityUtils.consume(entity1);// 释放响应response1.close(); // 2--------post登陆请求System.err.println("步骤2:向服务器发起post请求...");HttpPost httpPost2 = new HttpPost("http://3g.renren.com/login.do?autoLogin=true&");httpPost2.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3");//httpPost2.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0");// 封装post参数List<NameValuePair> nvps2 = new ArrayList<NameValuePair>();nvps2.add(new BasicNameValuePair("appid", ""));nvps2.add(new BasicNameValuePair("c", ""));nvps2.add(new BasicNameValuePair("email", email));nvps2.add(new BasicNameValuePair("lbskey", key));// 1中得到的keynvps2.add(new BasicNameValuePair("login", "登陆"));nvps2.add(new BasicNameValuePair("origURL", ""));nvps2.add(new BasicNameValuePair("password", password));nvps2.add(new BasicNameValuePair("pq", ""));nvps2.add(new BasicNameValuePair("ref", "http://m.renren.com/q.do?null"));httpPost2.setEntity(new UrlEncodedFormEntity(nvps2));CloseableHttpResponse response2 = httpclient.execute(httpPost2);System.out.println(" 状态-----"+response2.getStatusLine());/*所有头信息for(Header h:response2.getAllHeaders()){System.out.println(h.toString());}*///获取响应头的Location属性值---跳转地址Header location_h = response2.getFirstHeader("Location");String loc=location_h.getValue();System.out.println(" 跳转地址为"+loc);response2.close();//----------3跳转后------System.err.println("步骤3:正在跳转...");HttpGet get3 = new HttpGet(loc.trim());get3.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3");CloseableHttpResponse response3 = httpclient.execute(get3);System.out.println(" 状态is-----"+response3.getStatusLine());HttpEntity entity3=response3.getEntity();Document doc3=Jsoup.parse(EntityUtils.toString(entity3));//主页Elements url=doc3.select("form");String url3=url.attr("action");System.out.println("发状态的url为:-----"+url3);//发状态的url//获取发状态的参数String _rtk=doc3.select("input[name=_rtk]").attr("value");String sour=doc3.select("input[name=sour]").attr("value");String loginbybm=doc3.select("input[name=loginbybm]").attr("value");//String status=doc3.select("input[name=status]").attr("value");System.out.println(_rtk+sour+loginbybm);EntityUtils.consume(entity3);response3.close();Thread.sleep(3000);//4-----------------------发状态----------------------System.err.println("步骤4:发状态");HttpPost post4 = new HttpPost(url3);//忘写地址,活该post4.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3");List<NameValuePair> nvps4 = new ArrayList<NameValuePair>();nvps4.add(new BasicNameValuePair("_rtk", _rtk));nvps4.add(new BasicNameValuePair("loginbybm", ""));nvps4.add(new BasicNameValuePair("pid", ""));nvps4.add(new BasicNameValuePair("sour", sour));//String st=new String("今天心情真好!!!!!".getBytes(),"UTF-8");nvps4.add(new BasicNameValuePair("status", st));nvps4.add(new BasicNameValuePair("update", "发布"));post4.setEntity(new UrlEncodedFormEntity(nvps4));System.out.println(post4);CloseableHttpResponse response4 = httpclient.execute(post4);//?????????????System.out.println("-----");//获取响应头的Location属性值---跳转地址Header location_h4 = response4.getFirstHeader("Location");String loc4=location_h4.getValue();System.out.println(" 发状态跳转地址---"+loc4);response4.close();//5------------------发状态,跳转--------------------System.err.println("步骤5:正在跳转...");HttpGet get5 = new HttpGet(loc4.trim());get3.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3");CloseableHttpResponse response5 = httpclient.execute(get5);response5.close();System.err.println("发送成功!");} finally {httpclient.close();}}}
0 0
- 3g人人后台java登陆(httpclient4.4+jsoup)-初版
- httpclient/jsoup模拟登陆人人网
- HttpClient4使用(模拟登陆)
- HttpClient4.4 模仿登陆及维持同一session 请求
- java后台登陆的过滤
- HttpClient4.5+Jsoup实现抓取网页
- 运用jsoup和Java语言模拟登陆(入门级)
- 用户登陆 java后台处理(拦截器处理)
- selenium用java打开人人网并输入密码登陆
- selenium用java打开人人网并输入密码登陆
- selenium + jsoup 登陆网页
- 快速排序学习4(最初版加随机版)
- 人人网登陆之C++版(MFC)
- HttpClient模拟手机人人网登陆(一)---抓包
- python模拟登陆人人网(通过BeautifulSoup module)
- python 模拟登陆人人(比较垃圾大牛勿喷)
- matrix(c++实现,初版)
- Android计算器(最初版)
- JUnit2
- 记录一些软件学习的网站
- android的消息处理机制(图+源码分析)——Looper,Handler,Message
- KMP算法详解-----BY Matrix67
- android aidl 进程间通讯
- 3g人人后台java登陆(httpclient4.4+jsoup)-初版
- selenium-webdriver 使用WebDriverWait显示等待ajax交互
- Android系统开发中添加系统后门键
- jks密钥库容器操作 JKSUtilTest
- JUnit1
- java实现FIR线性缓冲区
- JKS和PKCS12密钥容器相互转换
- Makefile与shell脚本区别
- phonegap3+,https访问