Exemplo n.º 1
0
        private IEnumerable <string> TopRedditHeadlines_WithHext()
        {
            using (var client = new HttpClient())
            {
                string html = Task.Run(() => client.GetStringAsync("http://reddit.com")).Result;

                var doc = new HtmlDocument();
                doc.LoadHtml(html);

                var table = doc
                            .Body()
                            .ChildNodes.WithClass("content")
                            .ChildNodes.Last(node => node.Class() == "spacer")
                            .ChildNodes.WithId("siteTable");

                var posts = table.SortChildren(child => child.Class().Contains("thing"));

                foreach (var post in posts)
                {
                    string title = post
                                   .ChildNodes.WithClass("entry unvoted")
                                   .Element("p")
                                   .Element("a")
                                   .InnerText;

                    yield return(title);
                }
            }
        }