Quantcast
Channel: htmlagilitypack Forum Rss Feed
Viewing all articles
Browse latest Browse all 655

New Post: target images within a particular div issue

$
0
0

   Hi There

First of all, thanks for the people who spend time and energy on such projects.

Also, I seem to have a problem with the agilitypack.

1 - I am trying to get all the images from a particular div tag. (images might be embeded in other divs whithin this particular div), my problem is that all the images of the page are returned even the ones located outside the specified tag. Is there something wrong with my Xpath in there ?

here is my code

   string PromoLink = "http://www.myurl";
            HtmlWeb webPromo = new HtmlWeb();
            webPromo.PreRequest = new HtmlWeb.PreRequestHandler(OnPreRequest);
            string PromoUrl = PromoLink;
            HtmlDocument PromoDoc = webPromo.Load(PromoUrl);            
            HtmlNode extractDiv = PromoDoc.DocumentNode.SelectSingleNode("//div[@id='contentWrapper']");
            string PromoData = extractDiv.InnerHtml;
            var images = extractDiv.SelectNodes("//img[@src]");
            
            var nodes = new Dictionary<string, HtmlNode>();
                        
            foreach (var value in images)
            {
                                              
                string s = value.Attributes["src"].Value;
                
                if (!nodes.ContainsKey(s))
                {
                    nodes.Add(s, value);

                }

            }


Thanks a lot

Chris

 

 

 


Viewing all articles
Browse latest Browse all 655

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>