什么是正确的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).
更多推荐
发布评论