diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateExamInfoParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateExamInfoParser.java index 1a9b92e..d37b16d 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateExamInfoParser.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateExamInfoParser.java @@ -25,6 +25,8 @@ public class GraduateExamInfoParser implements Parser> { continue; } + scoreElements.removeIf(element -> element.hasClass("pagestopr")); + ExamInfo examInfo = new ExamInfo(); examInfo.setCourseName(infoGirds.get(0).text()); diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateTrainingPlanPageParser.java b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateTrainingPlanPageParser.java new file mode 100644 index 0000000..2dc4988 --- /dev/null +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/parser/postgraduate/GraduateTrainingPlanPageParser.java @@ -0,0 +1,34 @@ +package cn.linghang.mywust.core.parser.postgraduate; + +import cn.linghang.mywust.core.exception.ParseException; +import cn.linghang.mywust.core.parser.Parser; +import cn.linghang.mywust.core.util.JsoupUtil; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +public class GraduateTrainingPlanPageParser implements Parser { + + private static final String HTML_PREFIX = "培养计划"; + private static final String HTML_SUFFIX = ""; + + @Override + public String parse(String html) throws ParseException { + try { + Document document = Jsoup.parse(html); + Element fullTable = document.getElementById("Fin_Context"); + if (fullTable == null) { + throw new ParseException("解析研究生培养计划失败,元素Fin_Context不存在", html); + } + + String head = fullTable.getElementsByClass("pagestopl").get(0).outerHtml(); + String table = JsoupUtil.getOuterHtml(fullTable.getElementById("_ctl0_MainWork_dgData")); + String foot = JsoupUtil.getOuterHtml(fullTable.getElementById("Table4")); + + return HTML_PREFIX + head + table + foot + HTML_SUFFIX; + }catch (Exception e) { + // 解析失败就直接返回原网页展示 + return html; + } + } +} diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/request/graduate/GraduateRequestFactory.java b/mywust-core/src/main/java/cn/linghang/mywust/core/request/graduate/GraduateRequestFactory.java index 7091361..a24700c 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/request/graduate/GraduateRequestFactory.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/request/graduate/GraduateRequestFactory.java @@ -47,4 +47,8 @@ public class GraduateRequestFactory extends RequestFactory { public static HttpRequest examScoreInfoRequest(String cookie) { return makeHttpRequest(Graduate.GRADUATE_SCORE_API, null, cookie); } + + public static HttpRequest trainingPlanPageRequest(String cookie) { + return makeHttpRequest(Graduate.GRADUATE_TRAINING_PLAN_PAGE_API, null, cookie); + } } diff --git a/mywust-core/src/main/java/cn/linghang/mywust/core/util/JsoupUtil.java b/mywust-core/src/main/java/cn/linghang/mywust/core/util/JsoupUtil.java index 9711452..d925470 100644 --- a/mywust-core/src/main/java/cn/linghang/mywust/core/util/JsoupUtil.java +++ b/mywust-core/src/main/java/cn/linghang/mywust/core/util/JsoupUtil.java @@ -13,10 +13,15 @@ public class JsoupUtil { return element == null ? "" : element.text(); } + public static String getOuterHtml(Element element) { + return element == null ? "" : element.outerHtml(); + } + /** * 从Element中拿到指定的标签值 + * * @param element 元素对象 - * @param key 标签值的key + * @param key 标签值的key * @return 相应的值,若element为空则返回空字符串 */ public static String getAttr(Element element, String key) { @@ -29,6 +34,7 @@ public class JsoupUtil { /** * 从Element中拿到指定的文本内容 + * * @param element 元素对象 * @return 相应的值,若element为空则返回空字符串 */ @@ -42,6 +48,7 @@ public class JsoupUtil { /** * 从select类型的Element中拿取到已选中的选项值 + * * @param element 元素对象 * @return 相应的值,若element为空则返回空字符串 */