使用XPath:如何排除嵌套元素中的文本 [英] using XPath: how to exclude text in nested elements
本文介绍了使用XPath:如何排除嵌套元素中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有像下面这样的html:
if I have some html like the following
<div class=unique_id>
<h1 class="parseasinTitle">
<span> Game Title </span>
</h1>
Game Developer
</div>
有没有一种方法可以使用xpath来获取文本中的Game Developer部分?从周围搜索我试过:
Is there a way I can use xpath to get JUST the "Game Developer" part of the text? From searching around I tried:
//div[@class='unique_id' and not(self::h1/span)]
但仍然给了我全文Game Title Game Developer。
But that still gives me the entire text "Game Title Game Developer".
推荐答案
div[@class = 'unique_id']/text()[not(normalize-space() = '')]
或
div[@class = 'unique_id']/text()[last()]
取决于上下文。
请注意,您仍然需要修剪生成的文本节点。
Note that you still have to trim the resulting text node.
这篇关于使用XPath:如何排除嵌套元素中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文