knyazs
knyazs

Reputation: 99

HtmlAgilityPack - How to extract data?

How to get 1988 from the following HTML using HtmlAgilityPack:

<span class="year">Year: <strong class="">1988</strong></span>

I tried with:

.Descendants("span").Where(n => n.GetAttributeValue("class", "").Equals("year")).First().Attributes["strong"].DeEntitizeValue;

but null value is returned.

Upvotes: 0

Views: 174

Answers (1)

jira
jira

Reputation: 3944

You want InnerText of the strong element. In your example you could do just

SelectSingleNode("//strong").InnerText

Modify the strong selector appropriatelly for you use case.

Documentation here

Upvotes: 1

Related Questions