I am recently trying to develop a android app for my school friends so they do not have to use a web browser but an simple app to check their updated grades and exam schedule but since the school wont give permission to use their DB the only method is to do HTML parsing. so I found this library Jsoup and an example and started writing my own code but it always brings me the page source of login in page (It doesnt log in at all)
public Document getHTMLsoure() {
Document doc=null;
try {
doc = Jsoup.connect("http://karinca.meliksah.edu.tr")
.data("ctl00$ContentPlaceHolder1$txtKullaniciAdi","usernm")
.data("ctl00$ContentPlaceHolder1$txtSifre", "passwd")
.data("ctl00$ContentPlaceHolder1$btnLogin", "Giriş")
.userAgent("Mozilla")
.post();
} catch (IOException e1) {
e1.printStackTrace();
}
return doc; }
Please check it.
Result Kullanıcı adı yada şifre hatası !
Response res = Jsoup
.connect("https://karinca.meliksah.edu.tr/View/Login")
.userAgent("Mozilla")
.execute();
Document doc = res.parse();
String eventArgument = doc.select("input[name=__EVENTARGUMENT]").val();
String viewState = doc.select("input[name=__VIEWSTATE]").val();
String viewStateGenerator = doc.select("input[name=__VIEWSTATEGENERATOR]").val();
String eventValidation = doc.select("input[name=__EVENTVALIDATION]").val();
String asyncPost = "true";
String ct = "";
String body = doc.body().html();
int indexOf = body.indexOf("Sys.WebForms.PageRequestManager._initialize(");;
if(indexOf > -1){
int indexEnd = body.substring(indexOf).indexOf("');");
if(indexEnd > -1){
String temp = body.substring(indexOf, indexOf+indexEnd);
int indexStart = temp.lastIndexOf("'");
ct = temp.substring(indexStart+1,temp.length());
}
}
Document doc1 = Jsoup.connect("https://karinca.meliksah.edu.tr/View/Login.aspx")
.referrer("https://karinca.meliksah.edu.tr/View/Login")
.cookies(res.cookies())
.data(ct+"$ContentPlaceHolder1$ScriptManager2",ct+"$ContentPlaceHolder1$UpdatePanel1|"+ct+"$ContentPlaceHolder1$btnLogin")
.data(ct+"$ContentPlaceHolder1$txtKullaniciAdi","usernm")
.data(ct+"$ContentPlaceHolder1$txtSifre", "passwd")
.data("__EVENTTARGET",ct+"$ContentPlaceHolder1$btnLogin")
.data("__EVENTARGUMENT",eventArgument)
.data("__VIEWSTATE",viewState)
.data("__VIEWSTATEGENERATOR",viewStateGenerator)
.data("__EVENTVALIDATION",eventValidation)
.data("__ASYNCPOST",asyncPost)
.userAgent("Mozilla")
.post();
System.out.println(doc1.html());
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments