private void FetchPageCompleted(object sender, BaseEventArgs e) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(e.Result as string); string txt = doc.DocumentNode.SelectSingleNode("//table").InnerHtml; Page page = new Page(board); var r = PREV_START_RE.Match(e.Result as string); // TODO check PrevStart page.PrevStart = int.Parse(PREV_START_RE.Match(e.Result as string).Groups[2].ToString())-1; List<Header> headerList = new List<Header>(); var authorList = AUTHOR_RE.Matches(txt); var pidList = PID_RE.Matches(txt); var titleList = TITLE_RE.Matches(txt); var countList = COUNT_RE.Matches(txt); int diff = authorList.Count - countList.Count; // skip fixed posts, and append headers in reverse order for (int i = authorList.Count-1; i >= diff; i--) { Header h = new Header(); h.Author = authorList[i].Groups[1].ToString(); h.Board = page.Board; h.Pid = int.Parse(pidList[i].Groups[2].ToString()); h.Title = titleList[i].Groups[1].ToString().Remove(0, 2); h.ReplyCount = int.Parse(countList[i-diff].Groups[2].ToString()); h.ViewCount = int.Parse(countList[i-diff].Groups[4].ToString()); page.HeaderList.Add(h); } callback(this, new BaseEventArgs(page)); }
private void FetchHotListCompleted(object sender, BaseEventArgs e) { if (callback == null) return; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(e.Result as string); List<HeaderGroup> hotList = new List<HeaderGroup>(); var items = doc.DocumentNode.SelectNodes("//tr"); HeaderGroup grp = null; int sid = 0; foreach (var i in items) { if (i.SelectSingleNode("td/img") != null) { grp = new HeaderGroup(sid++); continue; } if (i.InnerHtml.StartsWith("<td>\n<tr><td colspan=\"2\">")) { hotList.Add(grp); continue; } MatchCollection matches = RE.Matches(i.InnerHtml); foreach (Match m in matches) { Header h = new Header(); h.Board = m.Groups[1].ToString(); h.Pid = int.Parse(m.Groups[2].ToString()); h.Title = m.Groups[3].ToString(); grp.Add(h); if (i.InnerHtml[m.Index + m.Length] == 'r') break; } } hotList.Add(grp); callback(this, new BaseEventArgs(hotList)); }