C# 如何使用XPath通过文本查找元素
我下载了HTML文档,我需要通过文本在树中查找元素 片段,仅相关部分C# 如何使用XPath通过文本查找元素,c#,html,xpath,html-agility-pack,C#,Html,Xpath,Html Agility Pack,我下载了HTML文档,我需要通过文本在树中查找元素 片段,仅相关部分 <div class="py-5 col-12"> <h4>Scale</h4> <div>
<div class="py-5 col-12">
<h4>Scale</h4>
<div>
<table class="table table-borderless">
<tbody>
<tr>
<th style="width: 300px;">Normalized Volume Percentile</th>
<td>
86<span style="position: relative; bottom: 1ex; font-size: 80%;">th</span>
</td>
</tr>
<tr>
<th>Combined Orderbook Percentile</th>
<td>
82<span style="position: relative; bottom: 1ex; font-size: 80%;">th</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
例外情况
System.Xml.XPath.XPathException: ''//Normalized Volume Percentile' has an invalid token.'
如果要按节点的文本内容定位节点,请尝试
"//th[.='Normalized Volume Percentile']"
要查找td
:
"//th[.='Normalized Volume Percentile']/following-sibling::td"
"//th[.='Normalized Volume Percentile']/following-sibling::td"