Select a node with a certain text value using htmlagilitypack

c# html-agility-pack hyperlink screen-scraping

Question

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!

Accepted Answer

Try using the text() function:

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


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why