我正在尝试使用 python-selenium 的 XPath。
I used 这个链接 http://www.jetairways.com/EN/SG/Home.aspx尝试教程中的一些 XPath:
所以我尝试了 XPath 的这两种变体。
-
这个表情
//webengagedata//preceding-sibling::*
返回 14 个结果
-
还有这个表情
//webengagedata/preceding-sibling::*
返回 9 个结果
“//”如何匹配另外 5 个结果?
/
vs //
一般来说
Both child
(/
) and descendant-or-self
(//
) are XPath 中的轴 https://www.w3.org/TR/1999/REC-xpath-19991116/#axes.
/
vs //
with preceding-sibling::*
您的具体问题询问之间的区别//preceding-sibling::*
and /preceding-sibling::*
.
由于您的数据是异地且复杂,因此让我们考虑一下现在的更简单的 XML:
<r>
<a/>
<b>
<c/>
<d/>
</b>
</r>
对于这个 XML,
-
/r/preceding-sibling::*
不选择任何内容,因为r
没有
前面的兄弟姐妹。
-
/r//preceding-sibling::*
选择前面的兄弟元素
所有后代或自己nodes of r
。那是,a
, b
, c
and d
。
(记住,/r//preceding-sibling::*
是缩写/descendant-or-self::node()/preceding-sibling::*
, not /descendant-or-self::*/preceding-sibling::*
)请注意,即使b
and d
是前任兄弟姐妹吗elements,他们是前辈兄弟姐妹文本节点因为上面的 XML 后面有空格b
and d
。如果所有空格都被删除,那么只有a
and c
将被选中。
-
/r/descendant::*/preceding-sibling::*
选择所有后代的前一个同级元素elements of r
。那是,a
and c
。注意b
and d
未选择,因为它们不是任何后代的同级元素elements of r
——与前面的例子不同的是,text节点不符合资格。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)