什么是正确的XPath表达式?(What is the right XPath expression?)

系统教程 行业动态 更新时间:2024-06-14 17:03:52
什么是正确的XPath表达式?(What is the right XPath expression?)

给出Wiki页面中的以下HTML:

<li> <a href="/wiki/Aluminium_bromide" title="Aluminium bromide">Aluminium bromide</a> – AlBr <sub>3</sub> </li>

XPath表达式应该是什么,能够返回:

的AlBr 3

我努力了:

string(//li[/a = "Aluminium bromide"]//-)

但它只是返回一个错误。

Given the following HTML from a Wiki page:

<li> <a href="/wiki/Aluminium_bromide" title="Aluminium bromide">Aluminium bromide</a> – AlBr <sub>3</sub> </li>

what should the XPath expression be, to be able to return:

AlBr3

I have tried:

string(//li[/a = "Aluminium bromide"]//-)

But it just returns an error.

最满意答案

这有点棘手,因为节点嵌套的方式。

但你可以说“ <li>里面的所有文本节点都包含一个值为'溴化铝'的<a> ,除了<a>本身的文本节点”。

//li[a = 'Aluminium bromide']//text()[not(parent::a)]

然后做一些后处理(加入,修剪等)。

That's a bit tricky because the way the nodes are nested.

But you could say "all text nodes inside the <li> that contains an <a> with a value of 'Aluminium bromide', except the text node of that <a> itself".

//li[a = 'Aluminium bromide']//text()[not(parent::a)]

and then do some post-processing (join, trim, etc).

更多推荐

本文发布于:2023-04-24 12:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/39f5cb97dcc8c060274f69103ee1ce5e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   正确   XPath   expression

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!