c# - 使用 htmlagilitypack 选择具有特定文本值的节点

标签 c# hyperlink screen-scraping html-agility-pack

所以我知道如何使用 htmlagilitypack 选择节点:

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

等等...但是说我有一个网站设置如下:

<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>

等...

现在,片段很短,但基本上,链接是不对称的,我只想访问具有文本值的链接

"this is information i want to get to"

(我对 hmtl 不够熟悉,无法在这里使用正确的术语,抱歉)。 htmlagilitypack 中是否有一种方法可以检查此文本值?

谢谢!

最佳答案

尝试使用 text() 函数:

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

关于c# - 使用 htmlagilitypack 选择具有特定文本值的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11085129/

相关文章:

c# - Sql 命令语法错误 : System. Data.SqlClient.SqlException: 'Incorrect syntax near ' ,'.'

c++ - Visual Studio中/GL和/LTCG有什么区别

javascript - 单击后悬停状态不起作用

python - 如何使用 python 和 Mechanize 模拟 AJAX 调用(XHR)

python - 使用 python 缩小我从网站上抓取的内容

c# - 按表达式树进行多列分组

c# - 为什么定义接口(interface)的方法和属性前面没有修饰符(public、private、protected)?

c# - 将资源从 dll 复制到 bin

html - 强制使用IE下载文件

python - python中的简单forvalues循环?