How do I parse HTML to find an anchor (<a />
) element with specific id
or class
or title
?
Ultimately, I want to find the value of the href
attribute.
How do I parse HTML to find an anchor (<a />
) element with specific id
or class
or title
?
Ultimately, I want to find the value of the href
attribute.
Here is an example
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(somehtmlstring);
string value = doc.DocumentNode.Descendants("a")
.First(n => n.Attributes["class"].Value == "someclass")
.Attributes["href"]
.Value;