如何指定返回没有最后一行的整个表的Xpath? [英] How to specify Xpath that return whole table without last row?

查看:283
本文介绍了如何指定返回没有最后一行的整个表的Xpath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是表格的代码。我需要提取没有最后一行的整个表。

Here is the code of a table. I need to extract whole table without last row.

整张桌子:

 <table class="product-content__table">
    <tr><th class="product-content__th">Состав</th><td>нержавеющая сталь, натуральная кожа </td></tr>
    <tr><th class="product-content__th">Ширина</th><td>2 см</td></tr><tr><th class="product-content__th">Цвет</th><td>серый </td></tr>
    <tr><th class="product-content__th">Страна производства</th><td>Россия </td></tr><tr><th class="product-content__th">Сезон</th><td>Мульти </td></tr>
    <tr><th class="product-content__th">Коллекция</th><td>Весна-лето </td></tr>
    <tr><th class="product-content__th">Артикул</th><td itemprop="sku">RO003DMCMA98</td></tr>
    </table>

我需要在没有这一行的情况下提取整个表:

I need to extract whole table without this row:

<tr><th class="product-content__th">Артикул</th><td itemprop="sku">RO003DMCMA98</td></tr>


推荐答案

< td> < th> 的兄弟,不是孩子所以你实际上并不需要 th in你的xpath。并且您希望在同一中过滤掉最后的 tr ,而不是过滤掉最后的 td 在同一 tr 中:

<td> is sibling of <th> not child so you don't actually need th in your xpath. And you want to filter out the last tr within the same table instead of filtering out the last td within the same tr :

//table[@class="product-content__table"]//tr[position() < last()]/td

删除尾随 / td 如果您想获得< tr> 的列表,而不是< td>

remove trailing /td if you want to get list of <tr> instead of <td>.

这篇关于如何指定返回没有最后一行的整个表的Xpath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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