Reputation: 904
I would like to find a span with a specific Id and retrieve the inner text. But I can't seem to find the way to do that.
can someone guide me with this
Upvotes: 4
Views: 8527
Reputation: 2801
I personally prefer to turn the whole thing into an XElement and query it that way when using Html Agility. Easier than xpath IMHO. But Darin's answer works
Upvotes: 1
Reputation: 1038820
You may try something along the lines:
var doc = new HtmlDocument();
doc.Load("foo.html");
var node = doc.DocumentNode.SelectSingleNode("//span[@id='foo']");
if (node != null)
{
var innerText = node.InnerText;
}
Upvotes: 14