gpt4 book ai didi

html - 如何使用 XPath 获取位置?

转载 作者:行者123 更新时间:2023-11-28 01:13:48 26 4
gpt4 key购买 nike

假设我有这样的 HTML 结构:

<table> 
<tr>...</tr>
<tr>...</tr>
<tr>
<td>111</td>
</tr>
<tr>
<td>222</td>
</tr>
</table>

如果我需要找到 <tr> 的数量,什么是正确的 XPath第一个标签 <tr><tr>标签有 /td[text()='111']

在我的示例中编号为 <tr>标签将为 3。

如果我们想查看 <tr> 的数量,结果将为 4从开始到<tr>其中有 "/td[@text='222']"

最佳答案

这个 XPath

count(//tr[td ='111']/preceding-sibling::tr) + 1

应用于此标记

<table> 
<tr>...</tr>
<tr>...</tr>
<tr>
<td>111</td>
</tr>
<tr>
<td>222</td>
</tr>
</table>

会回来

3

根据要求。

关于html - 如何使用 XPath 获取位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36581638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com