JAVA 模拟登陆华理教务处
来源:互联网 发布:solr默认端口号 编辑:程序博客网 时间:2024/05/16 18:52
概述
以前写过一个Python模拟登陆教务处的
现在来拿JAVA重写下
具体思路看那篇文章就好
不过这里还用了jsoup,那篇文章是正则表达式写
不过可以看出python比JAVA短太多了
Code
import org.apache.http.HttpEntity;import org.apache.http.NameValuePair;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.jsoup.Jsoup;import org.jsoup.nodes.Document;import org.jsoup.nodes.Element;import org.jsoup.select.Elements;import java.util.ArrayList;import java.util.List;import java.util.Scanner;class Jwc { final String LOGIN_URL = "http://202.120.108.14/ecustedu/K_StudentQuery/K_StudentQueryLogin.aspx"; final String LEFT_URL = "http://202.120.108.14/ecustedu/K_StudentQuery/K_StudentQueryLeft.aspx"; final String CLASS_TABLE_URL = "http://202.120.108.14/ecustedu/E_SelectCourse/ScInFormation/syllabus.aspx"; String username; String password; CloseableHttpClient client; Jwc(String a, String b) { username = a; password = b; } String getContent(String url) throws Exception{ HttpGet httpGet = new HttpGet(url); CloseableHttpResponse response = client.execute(httpGet); HttpEntity entity = response.getEntity(); Scanner scanner = new Scanner(entity.getContent()); String s = new String(); while (scanner.hasNextLine()) { s += (scanner.nextLine() + '\n'); } return s; } boolean init() throws Exception{ client = HttpClients.createDefault(); String s = getContent(LOGIN_URL); Document doc = Jsoup.parse(s); Elements es = doc.getElementsByTag("input"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); for (Element e : es) { String name = e.attr("name"); String value = e.attr("value"); if (name.equals("TxtStudentId")) value = username; if (name.equals("TxtPassword")) value = password; nvps.add(new BasicNameValuePair(name, value)); } HttpPost post = new HttpPost(LOGIN_URL); post.setEntity(new UrlEncodedFormEntity(nvps)); CloseableHttpResponse response = client.execute(post); String ss = getContent(LEFT_URL); if (ss.contains("您好")) return true; else return false; } String getClassTable() throws Exception{ String s = getContent(CLASS_TABLE_URL); Document doc = Jsoup.parse(s); Elements es = doc.getElementsByTag("input"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); for (Element e : es) { String name = e.attr("name"); String value = e.attr("value"); nvps.add(new BasicNameValuePair(name, value)); } HttpPost post = new HttpPost(CLASS_TABLE_URL); post.setEntity(new UrlEncodedFormEntity(nvps)); CloseableHttpResponse response = client.execute(post); Scanner scanner = new Scanner(response.getEntity().getContent()); String ss = new String(); while (scanner.hasNextLine()) { ss += scanner.nextLine(); } String res = new String(); doc = Jsoup.parse(ss); es = doc.select("tr"); for (Element e : es) { res += (e.text() + '\n'); } return res; }}public class Main { public static void main(String[] args) throws Exception { Jwc jwc = new Jwc("", ""); if (jwc.init()) { System.out.println(jwc.getClassTable()); } }}
0 0
- JAVA 模拟登陆华理教务处
- Python 模拟登陆华理教务处
- 模拟登陆教务处网站C#
- 使用Java模拟浏览器登陆网站(以抓取武汉理工大学教务处学生个人课表网页为例)
- 模拟登陆教务处-格式化输出(代码太凌乱)
- 模拟登陆西电研究生教务处(爬虫1)
- JAVA 模拟登陆华理体育
- HIT教务处登陆页面
- 可算是写好了自己的第一个教务处模拟登陆的代码了-.-
- php中CURL技术模拟登陆抓取数据实战,抓取某校教务处学生成绩。
- php实现模拟登陆带验证码并且重定向的教务处系统
- 人生苦短,我用Python--爬虫模拟登陆教务处并且保存数据到本地
- 模拟登陆学校教务处网站,并保存到成绩为excel格式
- 绕过验证码,模拟登录 南理教务处
- 模拟登入教务处(header)
- Python模拟登录东北大学教务处
- java如何模拟 登陆
- java模拟登陆
- 巧用ViewPager 打造不一样的广告轮播切换效果
- 【bzoj 1007】[HNOI2008]水平可见直线(计算几何)
- AJAX
- android基础--tools:context=".MainActivity"作用
- python numpy
- JAVA 模拟登陆华理教务处
- codeforcs 350 B. Game of Robots
- jQuery操作数组的工具方法
- 采用C#实现软件自动更新的方法
- php与数据库的连接运行
- MySQL学习6:MySQL基本数据类型
- Codeforces 665D Simple Subset【构造】
- sql server2008处理笛卡儿积的逻辑——记一次解决疑惑
- 这就是原因