From 9ba5ed71892636f319bfaf078a1cb406dccb6f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B9=BD=E5=96=B5?= <61258096+umeow0716@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:43:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=BE=A9=20=E6=88=90=E7=B8=BE?= =?UTF-8?q?=E6=9F=A5=E8=A9=A2=E5=8A=9F=E8=83=BD=20(#237)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix bug of get the title element in site QryScore.jsp * dart format --------- Co-authored-by: James-Lu-none --- lib/src/connector/score_connector.dart | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/src/connector/score_connector.dart b/lib/src/connector/score_connector.dart index 86136197..6c25c5a1 100644 --- a/lib/src/connector/score_connector.dart +++ b/lib/src/connector/score_connector.dart @@ -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"); @@ -209,6 +216,7 @@ class ScoreConnector { } } } + return courseScoreList; } catch (e, stack) { Log.eWithStack(e.toString(), stack);