xpath:有没有办法在 xpath 中获取所有孩子的文本 [英] xpath: Is there a way to get all the children's text in xpath

查看:23
本文介绍了xpath:有没有办法在 xpath 中获取所有孩子的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Firefox 上使用 xpath 引擎.我有 html:

I'm using the xpath engine on Firefox. I have html:

<span>
   <b>prefix one</b> not bold part
</span>
<span>
   prefix two not bold part
</span>

我想要所有具有以前缀一"开头的子文本的 span.

I want all the spans that have child text that start with "prefix one".

我尝试了 xpath:

I tried the xpath:

//span[starts-with(child::text(), "prefix one")]

但这不起作用,因为 b 标签会产生干扰.你如何解决这个问题?

but this doesn't work because the b tag is interfering. How do you solve this?

谢谢

推荐答案

如果你知道 spans 没有嵌套到其他 spans 你可以试试这个:

If you know that spans is not nested into other spans you can try this:

//span[ starts-with( descendant-or-self::*/text(),"prefix one" ) ]

descendant-or-self::*/text(), 应该返回这个子树中的所有文本节点.我不知道 starts-with() 是如何工作的,但我想当子树中的某些 text() 节点以前缀一"开头时,该条件为真

descendant-or-self::*/text(), should return all text nodes which are in this subtree. I don't know how starts-with() exactly works but I suppose when some of text() nodes in subtree starts with "prefix one" that condition is true

这篇关于xpath:有没有办法在 xpath 中获取所有孩子的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆