如何在两个节点之间选择文本 [英] How to select text between two nodes
本文介绍了如何在两个节点之间选择文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 Xpath 从网页中选择一些文本,但该文本位于两个节点之间.
I'd like to select some text from a webpage using Xpath, but this text is between two nodes.
...
<table>
<th>Abbreviation</th>
<tr>
<td>
<span><u>General</u><br/></span>
My Text <!--The text i want to get-->
<br/><u>Def</u>
Some other Text
</td>
</table>
...
请注意,我无法更改页面,因为它是我无法控制的来源.
Please note that i can't alter the page since it's a source that i can't control.
我已经浏览了 W3C 和维基百科文档,但没有找到任何(或理解的)内容.
I've already been through the W3C and wikipedia docs and dodn't found anything (or understood).
感谢您的回答
推荐答案
您可以使用以下 XPath 表达式.它搜索带有 u
子元素的 span
,然后选择下面的第一个文本.
You can use the following XPath expression. It searches for a span
with a u
child, then it selects the first following text.
//span[u]/following-sibling::text()[1]
这篇关于如何在两个节点之间选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文