Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 486
gfppaste Avatar asked Jun 18 '12 14:06

gfppaste


1 Answers

Try using the text() function:

SelectNodes("a[text()='This is information i want to get to']")
like image 55
Darin Dimitrov Avatar answered Sep 30 '22 17:09

Darin Dimitrov