Killercode
Killercode

Reputation: 904

HTML Agility Pack Find specific span

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

Answers (2)

kmcc049
kmcc049

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

Darin Dimitrov
Darin Dimitrov

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

Related Questions