Skip to content

Commit

Permalink
修復 成績查詢功能 (#237)
Browse files Browse the repository at this point in the history
* Fix bug of get the title element in site QryScore.jsp

* dart format

---------

Co-authored-by: James-Lu-none <jamesabcde277@gmail.com>
  • Loading branch information
umeow0716 and James-Lu-none authored Jul 24, 2024
1 parent c1d3978 commit 9ba5ed7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/src/connector/score_connector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,25 @@ class ScoreConnector {
}

tagNode = parse(result);
final h3Nodes = tagNode.getElementsByTagName("h3");
final titleNodes = tagNode.querySelectorAll("input[type=submit]");

//依照學期取得課程資料
for (final h3Node in h3Nodes) {
final siblingOfH3 = h3Node.nextElementSibling;
if (siblingOfH3 == null || siblingOfH3.localName != "table") continue;
final tableNode = siblingOfH3;
for (final titleNode in titleNodes) {
final siblingOfTitle = titleNode.parent.localName == "form"
? titleNode.parent.nextElementSibling
: // 當成績單已發布 父元素為form 父元素的旁邊元素才是 分數table
titleNode.nextElementSibling; // 當成績單未發布 父元素為body 原元素旁邊元素就會是 分數table

if (siblingOfTitle == null || siblingOfTitle.localName != "table") continue;
final tableNode = siblingOfTitle;

SemesterCourseScoreJson courseScore = SemesterCourseScoreJson();

SemesterJson semester = SemesterJson();
semester.year = h3Node.text.split(" ")[0];
semester.semester = h3Node.text.split(" ")[3];

String semesterText = titleNode.attributes["value"];
semester.year = semesterText.split(" ")[0];
semester.semester = semesterText.split(" ")[3];
courseScore.semester = semester;
//取得課程名稱與分數
scoreNodes = tableNode.getElementsByTagName("tr");
Expand Down Expand Up @@ -209,6 +216,7 @@ class ScoreConnector {
}
}
}

return courseScoreList;
} catch (e, stack) {
Log.eWithStack(e.toString(), stack);
Expand Down

0 comments on commit 9ba5ed7

Please sign in to comment.