Exemplo n.º 1
0
        private void Parse()
        {
            HtmlNode n = htmlDocument.GetElementbyId("news-main");

            //if (n != null)
            //{
                foreach (var node in n.ChildNodes)
                {
                    if (node.GetType() == typeof(HtmlNode) && node.HasAttributes)
                    {
                        if (node.Attributes["class"].Value == "g-section news sfe-break-bottom-16")
                        {
                            NewsFeed newsFeed = new NewsFeed();

                            foreach (var feedNode in node.ChildNodes)
                            {
                                if (feedNode.Attributes["class"].Value == "name")
                                {
                                    HtmlNode nn = HtmlNode.CreateNode(feedNode.InnerHtml);
                                    newsFeed.NewsLink = new Uri(nn.Attributes["href"].Value);
                                    newsFeed.Title = nn.InnerText;
                                }
                                else if (feedNode.Attributes["class"].Value == "byline")
                                {
                                    HtmlNode nn = HtmlNode.CreateNode(feedNode.InnerHtml);
                                    newsFeed.Source = nn.NextSibling.InnerText;
                                }
                                else if (feedNode.Attributes["class"].Value == "g-c")
                                {
                                    HtmlNode nn = HtmlNode.CreateNode(feedNode.NextSibling.InnerHtml);
                                    newsFeed.Snapshot = nn.InnerText;

                                    foreach (var nnn in nn.ChildNodes)
                                    {
                                        if (nnn.Attributes["class"].Value == "more-rel")
                                        {
                                            // TODO: really need to handle exceptions here.
                                        }
                                    }
                                }
                            }

                            NewsFeeds.Add(newsFeed);
                        }
                    }
                }
            //}
        }
Exemplo n.º 2
0
        private void Parse()
        {
            HtmlNode n = htmlDocument.GetElementbyId("news-main");

            //if (n != null)
            //{
            foreach (var node in n.ChildNodes)
            {
                if (node.GetType() == typeof(HtmlNode) && node.HasAttributes)
                {
                    if (node.Attributes["class"].Value == "g-section news sfe-break-bottom-16")
                    {
                        NewsFeed newsFeed = new NewsFeed();

                        foreach (var feedNode in node.ChildNodes)
                        {
                            if (feedNode.Attributes["class"].Value == "name")
                            {
                                HtmlNode nn = HtmlNode.CreateNode(feedNode.InnerHtml);
                                newsFeed.NewsLink = new Uri(nn.Attributes["href"].Value);
                                newsFeed.Title    = nn.InnerText;
                            }
                            else if (feedNode.Attributes["class"].Value == "byline")
                            {
                                HtmlNode nn = HtmlNode.CreateNode(feedNode.InnerHtml);
                                newsFeed.Source = nn.NextSibling.InnerText;
                            }
                            else if (feedNode.Attributes["class"].Value == "g-c")
                            {
                                HtmlNode nn = HtmlNode.CreateNode(feedNode.NextSibling.InnerHtml);
                                newsFeed.Snapshot = nn.InnerText;

                                foreach (var nnn in nn.ChildNodes)
                                {
                                    if (nnn.Attributes["class"].Value == "more-rel")
                                    {
                                        // TODO: really need to handle exceptions here.
                                    }
                                }
                            }
                        }

                        NewsFeeds.Add(newsFeed);
                    }
                }
            }
            //}
        }
Exemplo n.º 3
0
        private void Parse()
        {
            HtmlNode n = HtmlDocument.GetElementbyId("news-main");

            foreach (var node in n.ChildNodes)
            {
                if (node.GetType() == typeof(HtmlNode) && node.HasAttributes)
                {
                    if (node.Attributes["class"].Value == "g-section news sfe-break-bottom-16")
                    {
                        NewsFeed newsFeed = new NewsFeed();

                        foreach (var feedNode in node.ChildNodes)
                        {
                            if (feedNode.HasAttributes && feedNode.Attributes["class"].Value == "name")
                            {
                                HtmlNode nn = HtmlNode.CreateNode(feedNode.InnerHtml.Trim());
                                newsFeed.NewsLink = new Uri(nn.Attributes["href"].Value);
                                newsFeed.Title = nn.InnerText;
                            }
                            else if (feedNode.HasAttributes && feedNode.Attributes["class"].Value == "byline")
                            {
                                HtmlNode nn = HtmlNode.CreateNode(feedNode.InnerHtml);
                                newsFeed.Source = nn.NextSibling.InnerText;
                            }
                            else if (feedNode.HasAttributes && feedNode.Attributes["class"].Value == "g-c")
                            {
                                //HtmlNode nn=null;
                                foreach (var div in feedNode.ChildNodes)
                                {
                                    if (div.Name == "div")
                                    {
                                        newsFeed.Snapshot = HtmlNode.CreateNode(div.InnerHtml.Trim()).InnerText;
                                        //nn = div;
                                        break;
                                    }
                                }
                                
                                //HtmlNode nn = HtmlNode.CreateNode(feedNode.NextSibling.InnerHtml);
                                //newsFeed.Snapshot = nn.InnerText;

                                //if (nn != null)
                                //{
                                    foreach (var nnn in feedNode.ChildNodes)
                                    {
                                        //var i
                                        try
                                        {
                                            if (nnn.HasAttributes && nnn.Attributes["class"].Value == "more-rel")
                                            {
                                                newsFeed.RelatedNewsLinks.Add(new Uri(nnn.Attributes["href"].Value));
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            // Gobble the exception up. 
                                        }

                                    }
                                //}
                            }
                        }

                        NewsItems.Add(newsFeed);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void Parse()
        {
            HtmlNode n = HtmlDocument.GetElementbyId("news-main");

            foreach (var node in n.ChildNodes)
            {
                if (node.GetType() == typeof(HtmlNode) && node.HasAttributes)
                {
                    if (node.Attributes["class"].Value == "g-section news sfe-break-bottom-16")
                    {
                        NewsFeed newsFeed = new NewsFeed();

                        foreach (var feedNode in node.ChildNodes)
                        {
                            if (feedNode.HasAttributes && feedNode.Attributes["class"].Value == "name")
                            {
                                HtmlNode nn = HtmlNode.CreateNode(feedNode.InnerHtml.Trim());
                                newsFeed.NewsLink = new Uri(nn.Attributes["href"].Value);
                                newsFeed.Title    = nn.InnerText;
                            }
                            else if (feedNode.HasAttributes && feedNode.Attributes["class"].Value == "byline")
                            {
                                HtmlNode nn = HtmlNode.CreateNode(feedNode.InnerHtml);
                                newsFeed.Source = nn.NextSibling.InnerText;
                            }
                            else if (feedNode.HasAttributes && feedNode.Attributes["class"].Value == "g-c")
                            {
                                //HtmlNode nn=null;
                                foreach (var div in feedNode.ChildNodes)
                                {
                                    if (div.Name == "div")
                                    {
                                        newsFeed.Snapshot = HtmlNode.CreateNode(div.InnerHtml.Trim()).InnerText;
                                        //nn = div;
                                        break;
                                    }
                                }

                                //HtmlNode nn = HtmlNode.CreateNode(feedNode.NextSibling.InnerHtml);
                                //newsFeed.Snapshot = nn.InnerText;

                                //if (nn != null)
                                //{
                                foreach (var nnn in feedNode.ChildNodes)
                                {
                                    //var i
                                    try
                                    {
                                        if (nnn.HasAttributes && nnn.Attributes["class"].Value == "more-rel")
                                        {
                                            newsFeed.RelatedNewsLinks.Add(new Uri(nnn.Attributes["href"].Value));
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        // Gobble the exception up.
                                    }
                                }
                                //}
                            }
                        }

                        NewsItems.Add(newsFeed);
                    }
                }
            }
        }