0

我想知道我是否可以同时结合 XPath 寻找某个类的前一个兄弟与某个文本,同时将同一级别的兄弟与某个文本结合起来。

例如,我想找到以下单元格:

<td class="sdawatt_booknow"><a href="#" onclick="wa_class_book(160832)">Book</a></td>

通过查找sdawatt_hrdcell包含文本的类的兄弟姐妹,其前面是带有文本Spin的 td 类。sdawatt_bannerMonday - 16 September 2013

或以下 td:

    <td class="sdawatt_booknow"><a href="#" onclick="wa_class_book(160864)">Book</a></td>

如果我们查找“星期五 - 2013 年 9 月 13 日”的日期。

这在 Xpath 中可行吗?

<table cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse;" class="sdawatt_outer">
    <tbody><tr>
        <td class="sdawatt_hdrcell">Time</td>
        <td class="sdawatt_hdrcell">Class</td>
        <td class="sdawatt_hdrcell">Level</td>
        <td class="sdawatt_hdrcell">Spaces</td>
        <td class="sdawatt_hdrcell">Location</td>
        <td class="sdawatt_hdrcell">Instructors</td>
        <td class="sdawatt_hdrcell">Tags</td>
        <td class="sdawatt_hdrcell">Info</td>
        <td class="sdawatt_hdrcell">Book</td>
    </tr><tr>
        <td colspan="9" class="sdawatt_banner">Friday - 13 September 2013</td>
    </tr><tr class="sdawatt_classrow">
        <td class="sdawatt_time">07:45-08:15</td>
        <td class="sdawatt_classname">Boxing</td>
        <td class="sdawatt_level"> </td>
        <td class="sdawatt_spaces">14 Left</td>
        <td class="sdawatt_location">Main Studio</td>
        <td class="sdawatt_resources"> Darren</td>
        <td class=" sdawatt_infotags"></td>
        <td class="sdawatt_info"><img src="https://v4.fitnessandlifestylecentre.com/webaccess/TimetableView/information.gif" class="tiptip" /></td>
        <td class="sdawatt_booknow"><a href="#" onclick="wa_class_book(160848)">Book</a></td>
    </tr><tr class="sdawatt_classrow">
        <td class="sdawatt_time">12:00-12:45</td>
        <td class="sdawatt_classname">Spin</td>
        <td class="sdawatt_level"> </td>
        <td class="sdawatt_spaces">8 Left</td>
        <td class="sdawatt_location">Main Studio</td>
        <td class="sdawatt_resources"> Matt</td>
        <td class=" sdawatt_infotags"></td>
        <td class="sdawatt_info"><img src="https://v4.fitnessandlifestylecentre.com/webaccess/TimetableView/information.gif" class="tiptip" /></td>
        <td class="sdawatt_booknow"><a href="#" onclick="wa_class_book(160864)">Book</a></td>
    </tr><tr>
        <td colspan="9" class="sdawatt_banner">Monday - 16 September 2013</td>
    </tr><tr class="sdawatt_classrow">
        <td class="sdawatt_time">13:00-13:45</td>
        <td class="sdawatt_classname">Spin</td>
        <td class="sdawatt_level"> </td>
        <td class="sdawatt_spaces">12 Left</td>
        <td class="sdawatt_location">Main Studio</td>
        <td class="sdawatt_resources"> Marzena</td>
        <td class=" sdawatt_infotags"></td>
        <td class="sdawatt_info">
        <img src="https://v4.fitnessandlifestylecentre.com/webaccess/TimetableView/information.gif" class="tiptip" /></td>
            <td class="sdawatt_booknow"><a href="#" onclick="wa_class_book(160832)">Book</a></td>
    </tr>
</tbody></table>
4

1 回答 1

2
//tr[
        contains(
            td[@class="sdawatt_banner"],
            "Monday - 16 September 2013")
    ]
    /following-sibling::tr[
                           contains(
                               td[@class="sdawatt_classname"],
                               "Spin")
                          ]/td[@class="sdawatt_booknow"]

产量

<td class="sdawatt_booknow">
  <a href="#" onclick="wa_class_book(160832)">Book</a>
</td>
于 2013-09-12T20:53:41.590 回答