Example #1
0
        public static ForumTopicEntry ParseHtmlToTopic(HtmlNode topicRow, int tdOffset = 0)
        {
            var current = new ForumTopicEntry();
            var tds     = topicRow.Descendants("td").ToList();

            current.Type = tds[1].ChildNodes[0].InnerText;

            var titleLinks = tds[1].Descendants("a").ToList();
            var titleLink  = titleLinks[0].InnerText.Length == 0 ? titleLinks[1] : titleLinks[0];

            current.Title = WebUtility.HtmlDecode(titleLink.InnerText);
            var link = titleLink.Attributes["href"].Value;

            if (link.Contains("&goto="))
            {
                var pos = link.IndexOf("&goto=");
                link = link.Substring(0, pos);
            }

            current.Id = link.Split('=').Last();


            var spans = tds[1].Descendants("span").Where(node => !string.IsNullOrEmpty(node.InnerText)).ToList();

            current.Op      = spans[0].InnerText;
            current.Created = spans[1].InnerText;

            current.Replies = tds[2 + tdOffset].InnerText;

            current.LastPoster   = tds[3 + tdOffset].Descendants("a").First().InnerText;
            current.LastPostDate = tds[3 + tdOffset].ChildNodes.Last().InnerText;

            return(current);
        }
Example #2
0
        private static ForumTopicEntry ParseTopicRow(HtmlNode topicRow, int tdOffset = 0)
        {
            var current = new ForumTopicEntry();
            var tds     = topicRow.Descendants("td").ToList();

            current.Type = tds[1].ChildNodes[0].InnerText;

            var titleLinks = tds[1].Descendants("a").ToList();
            var titleLink  = titleLinks[1].InnerText == "»" ? titleLinks[2] : titleLinks[1];

            current.Title = WebUtility.HtmlDecode(titleLink.InnerText);
            var link = titleLink.Attributes["href"].Value;

            if (link.Contains("&goto="))
            {
                var pos = link.IndexOf("&goto=");
                link = link.Substring(0, pos);
            }
            else if (link.Contains("&goto="))
            {
                var pos = link.IndexOf("&goto=");
                link = link.Substring(0, pos);
            }

            current.Id = link.Split('=').Last();


            var spans = tds[1].Descendants("span").Where(node => !string.IsNullOrEmpty(node.InnerText)).ToList();

            try
            {
                var offset = 0;
                if (spans.Count == 3)
                {
                    offset = 1;
                }
                current.Op      = WebUtility.HtmlDecode(spans[offset].InnerText.Trim());
                current.Created = WebUtility.HtmlDecode(spans[1 + offset].InnerText.Trim());
            }
            catch (Exception e)
            {
                //html and specific indexes...
            }
            try
            {
                current.Replies = tds[2 + tdOffset].InnerText.Trim();

                current.LastPoster   = WebUtility.HtmlDecode(tds[3 + tdOffset].Descendants("a").First().InnerText.Trim());
                current.LastPostDate = tds[3 + tdOffset].ChildNodes.Last().InnerText.Trim();
            }
            catch (Exception)
            {
                //html and specific indexes...
            }


            return(current);
        }
 public ForumTopicEntryViewModel(ForumTopicEntry data)
 {
     Data = data;
 }