Xpath select 仅包含更多子项的标签文本

Xpath select only the text of tag that has more childs

我在页面中有这个块

    <h3 style="line-height:28px; margin-bottom:0px">
    <span style=" font-size:12px; background-color:#0050A1; padding:0 8px 0 8px;"> 
<a style="color:#FFF;">xxxxxx</a>
    </span>
    yyyyy
    </h3>

我想要yyyyy
我试过了

 //h3[@style='line-height:28px; margin-bottom:0px']text() 
 //h3[@style='line-height:28px; margin-bottom:0px']/following-sibling::text()
 //h3[@style='line-height:28px; margin-bottom:0px']//*[not(child::span)]
 //h3[@style='line-height:28px; margin-bottom:0px']text()[last()]

但什么都没有....

对于您显示的代码段,可以使用以下简单路径表达式:

//h3/text()[2]

转换为

//h3            Find h3 elements anywhere in the document
/text()         Find all text nodes of all `h3` elements
[2]             Only return the second of those text nodes

产生

⏎ (a newline character)
yyyyy

如果您需要更具体的 h3 元素,请使用

//h3[@style = 'line-height:28px; margin-bottom:0px']/text()[2]

当然,你并没有展示太多你的HTML,我只能猜测可能还有什么其他内容。


另外,您的问题标题:

Xpath select only the text of tag that has more childs

非常难懂。我不知道它与从文档中检索 "yyyyy" 有什么关系。