Beispiel #1
0
 private static ExamRoom ParseRoom(HtmlNode container, int row)
 {
     return(ExamRoom.Deserialize((new[] { 2, 4, 5, 6 }).Select((col) => {
         var parsed = HTMLUtils.ParseHTML(container, String.Format("tr[{0}]/td[{1}]", row, col));
         return parsed.FirstOrDefault()?.Replace(" ", "");
     })));
 }
 private static Grade ParseGrade(HtmlNode container, int row)
 {
     return(Grade.Deserialize((new[] { 3, 6, 8, 9, 10, 11 }).Select((col) => {
         var parsed = HTMLUtils.ParseHTML(container, String.Format("tr[{0}]/td[{1}]", row, col));
         return parsed.FirstOrDefault()?.Replace(" ", "");
     })));
 }
        public void LoadCourses(string html)
        {
            var document = new HtmlDocument();

            document.LoadHtml(html);
            var container = document.DocumentNode.SelectSingleNode("html/body/table/tr[2]/td/table/tr/td/table/tr/td/div/table");

            for (var col = 0; col < 6; ++col)     // course
            {
                for (var row = 0; row < 7; ++row) // weekdays
                {
                    var result = HTMLUtils.ParseHTML(container, String.Format("tr[{0}]/td[{1}]", col + 4, row + 2));
                    courses[row][col].Courses.AddRange(Course.Deserialize(result));
                }
            }

            Term        = String.Join(" ", HTMLUtils.ParseHTML(container, "tr[1]/td[1]"));
            StudentInfo = String.Join(" ", HTMLUtils.ParseHTML(container, "tr[2]/td[1]").First()
                                      .Split(new[] { "&nbsp;" }, StringSplitOptions.RemoveEmptyEntries)
                                      );
        }
        public void LoadGrades(string html)
        {
            var document = new HtmlDocument();

            document.LoadHtml(html);

            var parent = document.DocumentNode.SelectSingleNode("html/body/table/tr[2]/td/table");
            var info   = HTMLUtils.ParseHTML(parent, "tr/td/table/tr/td").First().Split(new[] { "&nbsp;", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            StudentInfo = String.Join(" ", info);

            var container = parent.SelectSingleNode("tr[2]/td/div/table");

            // class count text in html, has the form "共有记录数(\d+)"
            courses = Convert.ToInt32(Regex.Match(HTMLUtils.ParseHTML(container, "tr[last()]/td").First(), @"共有记录数(\d+)").Groups[1].Value);
            grades  = new Grade[courses];

            for (var row = 0; row < courses; ++row)
            {
                grades[row] = ParseGrade(container, row + 2);
            }
        }