Ejemplo n.º 1
0
        public static void ParseUser(HackerItem item, List <HtmlNode> links)
        {
            var userLink = links.Where(x => x.Attributes["href"].Value.Contains("user")).ToList();

            if (userLink.Count >= 1)
            {
                item.User = userLink[0].InnerText;
            }
        }
Ejemplo n.º 2
0
        public static void ParseTitle(HackerItem item, List <HtmlNode> links)
        {
            HtmlNode link;

            if (links.Count == 3)
            {
                link = links[1];
            }
            else
            {
                link = links[0];
            }

            item.Title = link.InnerText;
        }
Ejemplo n.º 3
0
        public static void ParseUrl(HackerItem item, List <HtmlNode> links)
        {
            HtmlNode link;

            if (links.Count == 3)
            {
                link = links[1];
            }
            else
            {
                link = links[0];
            }

            item.URL = link.Attributes["href"].Value;
        }
Ejemplo n.º 4
0
        protected List <HackerItem> ParseList(List <HtmlNode> rows)
        {
            List <HackerItem> items    = new List <HackerItem>();
            HackerItem        newsItem = null;

            newsItem = new HackerItem();
            for (int i = 0; i < rows.Count; i++)
            {
                try
                {
                    var row       = rows[i];
                    var tableData = row.Descendants("td");

                    if (tableData != null && tableData.Count() > 0)
                    {
                        if (tableData.Count(x => x.Attributes["class"] != null && x.Attributes["class"].Value.Contains("title")) > 0)
                        {
                            if (i == rows.Count - 1)
                            {
                                nextUrl = row.Descendants("a").ToList()[0].Attributes["href"].Value;
                                break;
                            }

                            ParsingHelpers.ParseUrl(newsItem, row.Descendants("a").ToList());
                            ParsingHelpers.ParseTitle(newsItem, row.Descendants("a").ToList());
                        }
                        else if (tableData.Count(x => x.Attributes["class"] != null && x.Attributes["class"].Value.Contains("subtext")) > 0)
                        {
                            var links = row.Descendants("a").ToList();
                            ParsingHelpers.ParseUser(newsItem, links);
                            if (newsItem.Title != "")
                            {
                                items.Add(newsItem);
                            }

                            newsItem = new HackerItem();
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new HackerException("Could not parse the news feed. See inner exception for details", e);
                }
            }

            return(items);
        }