的XPath 2个的某些元素

我有这样的HTML页面之间选择元素:的XPath 2个的某些元素

<tr class="facts_label"></tr> 

<tr class="facts_label"></tr>

<tr class="other_label"></tr>

<tr class="facts_label"></tr>

<tr class="facts_label"></tr>

<tr class="other_label"></tr>

<tr class="other_label"></tr>

<tr class="facts_label"></tr>

<tr class="facts_label"></tr>

<tr class="other_label"></tr> # Select this

<tr class="other_label"></tr> # Select this

<tr class="facts_label"></tr>

<tr class="other_label"></tr>

<tr class="other_label"></tr>

我要选择带班的TR元素“other_label”这是最后2个TR元素与类“facts_label”之间

我想:

'//tr[@class="other_label" and (preceding-sibling::tr[@class="facts_label"][last()-1]) and (following-sibling::tr[@class="facts_label"][last()])]' 

但是,这是我得到

<tr class="facts_label"></tr> 

<tr class="facts_label"></tr>

<tr class="other_label"></tr> # Got this

<tr class="facts_label"></tr>

<tr class="facts_label"></tr>

<tr class="other_label"></tr> # Got this

<tr class="other_label"></tr> # Got this

<tr class="facts_label"></tr>

<tr class="facts_label"></tr>

<tr class="other_label"></tr> # Got this

<tr class="other_label"></tr> # Got this

<tr class="facts_label"></tr>

<tr class="other_label"></tr>

<tr class="other_label"></tr>

回答:

的XPath “绝招”:

//tr[ @class='other_label' and count(following-sibling::tr[@class='facts_label'])=1 ] 

以上是 的XPath 2个的某些元素 的全部内容, 来源链接: utcz.com/qa/258106.html

回到顶部