gfppaste
gfppaste

Reputation: 1121

Select a node with a certain text value using htmlagilitypack

So I'm aware of how to select a node using htmlagilitypack:

HtmlNode.SelectNodes(".//div[@class='description']")

etc... but say I have a site set up in the following way:

<a href="/link1/">This is Link 1</a>
<a href="/link2/">This is information i want to get to</a>
<a href="/link3/">This is Link 3</a>
<a href="/link4/">This is information i want to get to</a>
<a href="/link5/">This is Link 5</a>
<a href="/link6/">This is Link 6</a>

etc...

Now, the snippet is short, but basically, The links are asymmetric, and I only want to access links that have the text value

"this is information i want to get to"

(I'm not familiar enough with hmtl to use proper terminology here, sorry). Is there a method in htmlagilitypack where I can check this text value?

Thank you!

Upvotes: 6

Views: 6910

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

Try using the text() function:

SelectNodes("a[text()='This is information i want to get to']")

Upvotes: 18

Related Questions