我在 AsyncTask 类中有以下代码(目的是登录到我的学生成绩簿,检索成绩,现在输出到日志):
private class infoGetter extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
String studentID = studentID2.getText().toString();
String username = user.getText().toString();
String password = pass.getText().toString();
String loginURL = "https://parents.mtsd.k12.nj.us/genesis/parents/j_security_check";
String userDataUrl = "https://parents.mtsd.k12.nj.us/genesis/parents?module=" + module + "&action=" + action + "&mpToView=" + mp + "&studentid=" + studentID;
Connection.Response res = null;
Document doc = null;
try {
res = Jsoup.connect(userDataUrl)
.userAgent("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.4 Safari/537.36")
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
.timeout(500)
.method(Connection.Method.GET)
.execute();
Log.e("connecting","first connection");
} catch (IOException io) {
io.printStackTrace();
}
try {
doc = Jsoup.connect(loginURL)
.userAgent("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.4 Safari/537.36")
.referrer("https://parents.mtsd.k12.nj.us/genesis/parents?gohome=true")
.cookies(res.cookies())
.data("j_username", username)
.data("j_password", password)
.post();
Log.e("connecting","second connection");
} catch (IOException ioe) {
ioe.printStackTrace();
}
Log.e("connecting","about to check if doc is null");
if (doc != null){
Log.e("MESSAGE","doc is not null");
//everything works fine up to here!!
Elements fGrade = doc.select("[width=70%]");
for(Element e : fGrade) {
Log.e("Grade: ",e.text());
}
}
return null;
}
}
}
但是,在运行我的应用程序并登录(正确的凭据)后,我根本没有收到任何包含我的成绩的日志消息。我的 Jsoup 代码应该是正确的,因为我使用 java 创建了一个测试项目作为我的应用程序的前言,该项目运行完美。但是,我不知道我做错了什么!
一如既往地感谢所有帮助!
更新:因此,使用不同的日志,我已将错误范围缩小到我使用“doc.select()”调用周围/之后的某个点。不过我还是没看出有什么问题..
最佳答案
好吧,事实证明我的学校决定更新他们的成绩簿的用户界面,所以我的查询实际上是不正确的。更新后的查询一切正常。
关于java - Android应用程序不显示解析的Jsoup信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31766811/