import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class moni {
public static void main(String[] args) throws IOException {
//Scanner sc=new Scanner(System.in);
//test test=new test();
String url="http://jwgl.just.edu.cn:8080/jsxsd/";
Connection con=Jsoup.connect(url).timeout(30000);
Response re=con.execute();
Document doc=Jsoup.parse(re.body());
Elements link=doc.select("form");
Elements links=link.select("input");
Map map = new HashMap<>();
for(Element e:links)
{
if(e.attr("name").equals("USERNAME"))
{
e.attr("value","162210702210");
}
if(e.attr("name").equals("PASSWORD"))
{
e.attr("value","285511");
}
if(e.attr("name").length()>0) {map.put(e.attr("name"), e.attr("value"));}
}
//登陆部分
Connection con2=Jsoup.connect(url "xk/LoginToXk").cookies(re.cookies()).timeout(2000);
con2.data(map);
con2.followRedirects(true);
con2.method(Method.POST);
Response re2=con2.execute();
System.out.println("succss");
// /*
// * 登陆成功
// */
String url3=url "xspj/xspj_find.do?Ves632DSdyV=NEW_XSD_JXPJ";
Connection con3=Jsoup.connect(url3).timeout(2000);
con3.header("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36");
con3.header("Connection", "keep-alive");
con3.cookies(re.cookies());
Response res3=con3.ignoreContentType(true).method(Method.GET).execute();
Document doc3=Jsoup.parse(res3.body());
Elements elements=doc3.select("td a[href]");
String shiyan="http://jwgl.just.edu.cn:8080" elements.get(0).attr("href");
String lilun="http://jwgl.just.edu.cn:8080" elements.get(2).attr("href");
judgle(shiyan,re.cookies());//实验课理论课评教
judgle(lilun,re.cookies());
// System.out.println(shiyan);
}
private static void judgle(String url, Map cookies) throws IOException {
// TODO 自动生成的方法存根
Document doc=Jsoup.connect(url).cookies(cookies).get();
Elements elements=doc.select("td a[href]");
ExecutorService ex= Executors.newFixedThreadPool(10);
int i=0;
for(Element e:elements)
{
String judurl=e.attr("href");
//javascript:JsMod('/js.................pe=view',1000,700)需要正则匹配//我直接用字符串切割
String judur[]=judurl.split("'");
judurl="http://jwgl.just.edu.cn:8080" judur[1];
try {
judThread judThread=new judThread(judurl, cookies);
ex.execute(judThread);
//judteacher(judurl,cookies);
} catch (Exception e2) {
System.out.println(e2);
}
}
ex.shutdown();
}
static class judThread implements Runnable{
String url;
Mapcookies;
public judThread(String url,Map map ) {
this.url=url;
this.cookies=map;
}
@Override
public void run() {
// TODO Auto-generated method stub
try {
judteacher(url, cookies);
System.out.println(Thread.currentThread().getName() " jud" url);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private static void judteacher(String judurl, Map cookies) throws IOException {
// TODO 自动生成的方法存根
Document doc=Jsoup.connect(judurl).cookies(cookies).get();
Elements link=doc.select("form");
String actionurl="http://jwgl.just.edu.cn:8080" link.attr("action");
Elements links=link.select("input");
Mapmap=new TreeMap<>();
for(Element e:links)//先处理所有隐藏的参数
{
if(e.attr("type").equals("hidden"))
{
map.put(e.attr("name"),e.attr("value"));
}
}
Elements links2=link.select("#table1 tr");
int index=0;//第一个不是参数
for(Element e:links2)//处理button类元素
{
if(index==0) {index ;continue;}
else if(index==links2.size()-1){
String text=e.select("textarea").first().attr("name");
map.put(text, "老师很认真负责!");
}
else if(index==1) {
Elements ele=e.select("input[type=radio]");
Element NO2=ele.get(1);
map.put(NO2.attr("name"), NO2.attr("value"));
//System.out.println(NO2.attr("name"));
}
else {
Elements ele=e.select("input[type=radio]");
Element NO1=ele.get(0);
map.put(NO1.attr("name"), NO1.attr("value"));
//System.out.println(NO1.attr("name"));
}
index ;
//System.out.println(e);
}
map.put("tj", "提 交");
//最后提交form表单
for(String a:map.keySet())
{
System.out.println(a " " map.get(a));
}
Mapmap2=new HashMap<>();
Mapmap3=new HashMap<>();
Mapmap4=new HashMap<>();
Mapmap5=new HashMap<>();
map.put("pj06xh", "1");
map2.put("pj06xh", "2");
map3.put("pj06xh", "3");
map4.put("pj06xh", "4");
map5.put("pj06xh", "5");
map.put("issubmit", "1");
Connection con4=Jsoup.connect(actionurl).cookies(cookies).timeout(2000);
con4.data(map).data(map2).data(map3).data(map4).data(map5);
con4.referrer(judurl);
Response res4=con4.method(Method.POST).execute();
}
}