如何获取前面的元素? [英] How to get the preceding element?

查看:23
本文介绍了如何获取前面的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<p class="small" style="margin: 16px 4px 8px;">
<b>
<a class="menu-root" href="#pg-jump">Pages</a>
 :  
<b>1</b>
, 
<a class="pg" href="viewforum.php?f=941&start=50">2</a>
, 
<a class="pg" href="viewforum.php?f=941&start=100">3</a>
 ... 
<a class="pg" href="viewforum.php?f=941&start=8400">169</a>
, 
<a class="pg" href="viewforum.php?f=941&start=8450">170</a>
, 
<a class="pg" href="viewforum.php?f=941&start=8500">171</a>
<a class="pg" href="viewforum.php?f=941&start=50">Next.</a>
</b>
</p>

我想捕获包含 171 的 a 元素.所以基本上是 Next 中的前一个元素.

I want to catch a element containing 171. So basically the preceding element from the Next.

//a[.='Next.']//Not sure how to use preceding here

推荐答案

你可以使用这个 xpath:

//a[.="Next."]/preceding::a[1]

<小时>

如果我要绘制它,使用 X 表示当前位置,它看起来像这样:


If I were to diagram it out, using an X to represent the current location, it would look like this:

------------------+------+------------------
preceding-sibling | self | following-sibling
------------------|------|------------------
last() ...  2   1 |  X   | 1   2  ... last()
------------------+------+------------------

这篇关于如何获取前面的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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