更正XPath查询以提取div内部文本 [英] Correct XPath query to fetch div inner text
问题描述
我使用XPath查询HTML文档,其中有下面的div有文本:
< div class = h1> 2008本田Accord Coupe< small> - Wuse II< / small>< / div>
我只想获取的内部文本< div class = h1> 2008本田雅阁Coupe
,不包括< small>内部文字< / small>
我正在做以下XPath查询: // div [@ class ='h1']
这肯定会返回整个 < div> ...< / div>
节点。
如何获取没有< small> ...< / small>
感谢 I am using XPath to query into HTML document where there is following div has text: I wanted to fetch only the inner text of the I am making following XPath query: How can I only fetch portion without thanks Use the Tested in phpFiddle 这篇关于更正XPath查询以提取div内部文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! / code> function:
// div [@ class ='h1' ] / text()
<div class="h1">2008 Honda Accord Coupe<small> — Wuse II</small></div>
<div class="h1">2008 Honda Accord Coupe
and not include the <small>inner text</small>
//div[@class='h1']
which is definitely returning entire <div>...</div>
node. <small>...</small>
text()
function://div[@class='h1']/text()