-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsoupTester.java
99 lines (78 loc) · 3.52 KB
/
JsoupTester.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.io.IOException;
import java.util.HashMap;
import org.jsoup.Jsoup;
import org.jsoup.Connection;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.util.Iterator;
import org.jsoup.select.Elements;
import java.util.Map;
public class JsoupTester {
public static void main(String[] args) throws IOException {
final String USER_AGENT = "\"Mozilla/5.0 (Windows NT\" +\n" + " \" 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2\"";
String loginFormUrl = "https://www.rajagiritech.ac.in/stud/Parent/";
String loginActionUrl = "https://www.rajagiritech.ac.in/stud/Parent/varify.asp";
String username = "u1603149";
String password = "160147";
HashMap<String, String> cookies = new HashMap<>();
HashMap<String, String> formData = new HashMap<>();
Connection.Response loginForm = Jsoup.connect(loginFormUrl).method(Connection.Method.GET).userAgent(USER_AGENT).execute();
Document loginDoc = loginForm.parse(); // this is the document that contains response html
cookies.putAll(loginForm.cookies()); // save the cookies, this will be passed on to next request
formData.put("user", username);
formData.put("pass", password);
formData.put("I1.x", "0");
formData.put("I1.y", "0");
Connection.Response homePage = Jsoup.connect(loginActionUrl)
.cookies(cookies)
.data(formData)
.method(Connection.Method.POST)
.userAgent(USER_AGENT)
.execute();
Document afterLogin = homePage.parse();
Elements links = afterLogin.getElementsByClass("scroller");
String scrollerText = links.text();
String[] arr = scrollerText.split(" : ");
String name = new String(arr[1]);
scrollerText=null;
arr=null;
System.out.println(name+"\n\n\n");
cookies.clear();
cookies.putAll(homePage.cookies());
Document doc = Jsoup.connect("https://www.rajagiritech.ac.in/stud/KTU/Parent/Leave.asp")
.timeout(5000)
.data("code","2019S6CS-C")
.cookies(cookies)
.get();
//System.out.println(doc.html());
Element classesMissed = doc.select("td").first();
String str = new String(classesMissed.text());
Map<String, Integer> map = new HashMap<String, Integer>();
int counter = 0;
String sub;
int stringLen = str.length() - 4;
for (int i = 0; i < stringLen ; i++) {
sub = str.substring(i, i + 5);
if (map.containsKey(sub)) {
counter = map.get(sub);
counter++;
map.put(sub, counter);
counter = 0;
} else {
map.put(sub, 1);
}
}
//System.out.println(map.keySet().toString());
map.entrySet().removeIf(entry -> entry.getKey().contains("-"));
map.entrySet().removeIf(entry -> entry.getKey().contains(" "));
map.entrySet().removeIf(entry -> entry.getKey().contains("a"));
map.entrySet().removeIf(entry -> entry.getKey().contains("9S"));
map.entrySet().removeIf(entry -> entry.getKey().contains("18"));
map.entrySet().removeIf(entry -> entry.getKey().contains("17"));
map.entrySet().removeIf(entry -> entry.getValue().toString().equals("1"));
map.forEach((key, value) -> System.out.println(key + ":" + value));
//for (Element cl:classesMissed){
// System.out.println(cl.text());
//}
}
}