gpt4 book ai didi

用于识别未标记文本的 XPath 查询

转载 作者:行者123 更新时间:2023-12-03 15:52:24 25 4
gpt4 key购买 nike

考虑这个 HTML:

<html>
<head>
</head>
<body>
<table>
<tr>
<td>
<h1>title</h1>
<h3>item 1</h3>
text details for item 1
<h3>item 2</h3>
text details for item 2
<h3>item 3</h3>
text details for item 3
</td>
</tr>
</table>
</body>
</html>

我对 XPath 不是很熟悉,但在我看来,没有一种符号可以单独匹配“文本详细信息”部分。你能证实吗?

最佳答案

使用:

/html/body/table/tr/td/h3/following-sibling::text()[1]

这意味着:获取作为每个 tr 元素的子元素的每个 h3 元素的第一个后续同级文本节点,该元素是每个 table< 的子元素 元素是每个 body 元素的子元素,该元素是 html 顶级元素的子元素。

或者,如果您只知道所需的文本节点是文档中所有 h3 元素 的紧随其后的兄弟节点,则此 XPath 表达式会选择它们:

//h3/following-sibling::text()[1]

关于用于识别未标记文本的 XPath 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4083466/

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