Android模拟登陆综合教务系统客户端(java)-jsoup解析数据
来源:互联网 发布:淘宝店铺绑定旺旺 编辑:程序博客网 时间:2024/09/21 08:57
现如今,基本的app都需要接入网络,下面介绍如何模拟登陆学校的教务系统获得里面的内容。
有Http基础的朋友都知道,我们是通过Get 与Post请求与服务器进行交互的,Get顾名思义就是获取信息,Post就是想服务器发请求,但是Post也可以用来获取信息并且比Get有很多优势,我们这里就是使用的Post。Java中有很多方式与服务器进行连接,常见的有HttpUrlCollection,HttpClient。两者的优缺点:
需要用到的工具:httpwatch (适用于火狐和IE浏览器)用于获得postdata.
1.如何获取验证码
private void DoGetVerifation() { new Thread(new Runnable() { @Override public void run() { HttpPost httPost = new HttpPost(VERIFATIONURL); HttpClient client = new DefaultHttpClient(); try { HttpResponse httpResponse = client.execute(httPost); byte[] bytes = new byte[1024]; bytes = EntityUtils.toByteArray(httpResponse.getEntity()); bmVerifation = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); } catch (IOException e) { e.printStackTrace(); } if (bmVerifation == null) { Looper.prepare() Toast.makeText(MainActivity.this, "获取验证码失败请检查网络设置", Toast.LENGTH_SHORT).show(); Looper.loop() } Message msg = new Message(); msg.arg1 = 10; handler.sendMessage(msg); } }).start(); }
2.
post登陆信息
<pre name="code" class="java"> private void DoLogin(final String user, final String password, final String verifation) { new Thread(new Runnable() { @Override public void run() { DefaultHttpClient defaultclient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(LOGINURL); httpPost.setHeader("Cookie", Cookie); HttpResponse httpResponse; //设置post参数 List<NameValuePair> params = new ArrayList<NameValuePair>(); String inputText_user = userName.getText().toString(); String inputText_password = passWord.getText().toString(); String inputText_yanzhengma = yanzhengma.getText().toString(); params.add(new BasicNameValuePair("groupId", "")); params.add(new BasicNameValuePair("j_username", user)); params.add(new BasicNameValuePair("j_password", password)); params.add(new BasicNameValuePair("j_captcha", verifation)); params.add(new BasicNameValuePair("login", "登录")); //获得个人主界面的HTML try { httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); httpResponse = defaultclient.execute(httpPost); Log.i("xyz", String.valueOf(httpResponse.getStatusLine().getStatusCode())); if (httpResponse.getStatusLine().getStatusCode() == 200) { StringBuffer sb = new StringBuffer(); HttpEntity entity = httpResponse.getEntity(); MAINBODYHTML = EntityUtils.toString(entity); Log.d("I",MAINBODYHTML); //Toast.makeText(bangdingActivity.this, MAINBODYHTML, Toast.LENGTH_SHORT).show(); IsLoginSuccessful(MAINBODYHTML); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }).start(); }
里面的parm参数需要通过httpwatch获取到postdata得到属性。创建post,client response,与前面无异,我们获取数据的Post请求,比如说获取验证码请求是不需要参数的,但是我们登录需要发送给服务器 用户名 密码 验证码,于是我们为Post请求设置参数。
获取到POST DATA就是需要上传的params
3.jsoup解析html
private void IsLoginSuccessful(String loginresult){ Document doc = Jsoup.parse(loginresult); Message msg = new Message(); //先判断是否登录成功,若成功直接退出 Elements el = doc.select("div[id=error]"); if(el.text().contains("您输入的验证码不正确")){ Log.d("xyz", "验证码错误"); msg.arg1 = 0; handler.sendMessage(msg); } else if(el.text().contains("密码不匹配")) { Log.d("xyz", "密码不匹配"); msg.arg1 = 2; handler.sendMessage(msg); } else if(el.text().contains("用户名")){ Log.d("1","用户名不存在"); msg.arg1 = 5; handler.sendMessage(msg); } else{ msg.arg1 = 6; handler.sendMessage(msg); } }
1 0
- Android模拟登陆综合教务系统客户端(java)-jsoup解析数据
- Android实现模拟登陆教务系统并解析网页数据
- 【JAVA】模拟登陆教务系统
- 关于Android端模拟登陆教务系统
- Android模拟登陆校园教务系统
- java 模拟登陆正方教务系统
- JAVA模拟正方教务系统登陆
- java模拟登陆正方教务管理系统
- android模拟登陆正方教务
- Android 模拟登陆正方教务系统(一)
- Java--使用httpClient模拟登陆正方教务系统获取课表
- 【Android+OkHttp3+Jsoup】 模拟登录教务系统 抓取课表和成绩
- Python 模拟登陆教务选课系统
- php模拟登陆青果教务系统
- Java实现从正方教务系统抓取数据(三)--Android客户端
- 针对 android端模拟教务系统登陆,主要针对抓包过程,post,get请求,和解析网页和cookie(一)
- 针对 android端模拟教务系统登陆,主要针对抓包过程,post,get请求,和解析网页和cookie(二)
- android jsoup解析服务端数据客户端源码讲解。
- 小米手机server内部调用alertdialog不显示问题
- vscode快捷键大全
- 面试题
- 实时监控textview输入的方法
- Android Studio开发环境建立aidl文件,生成相应的java文件
- Android模拟登陆综合教务系统客户端(java)-jsoup解析数据
- Java中调用Windows API的方法
- iOS 横屏的问题,相信很多新手朋友都是懵懵懂懂
- 数据结构与算法JavaScript - 二叉树和二叉查找树
- spring boot入门 (3)--Maven 打包
- Servlet常见错误及解决方法
- hokuyo 01LX激光传感器驱动程序的安装和创建地图时出现的问题
- 代码笔记
- android插件化学习笔记(二)