我在页面中有这个块
<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()]
但没有......
答案 0 :(得分:1)
对于您显示的代码段,以下简单路径表达式将执行:
//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仅选择包含更多子项的标记文本
非常难以理解。我不知道它与从文档中检索“yyyyy”有什么关系。