Sundara Rajan C
Sundara Rajan C

Reputation: 63

Website parsing c# - Html Agility Pack

I want to parse <a href=""></a> tag of a website. I am trying to get the href attribute value present in each of such 'description' span classes.

enter image description here

I tried the following code

HtmlNodeCollection sp = htmlDocument.DocumentNode.SelectNodes("//span[@class='description']//a");
                        foreach (HtmlNode link in sp)
                        {
                            HtmlAttribute att = link.Attributes["href"];
                            System.Diagnostics.Debug.WriteLine(att.Value);
                        }

I am not able to get the href attribute value. What is my mistake ?

Upvotes: 0

Views: 218

Answers (1)

sheauren
sheauren

Reputation: 96

enter image description here You can use chrome developer tools (F12), it can help you easy to get correct xPath syntax (Copy XPath)

Upvotes: 2

Related Questions