xpath:搜索html表行中的节点(多个条件)

时间:2014-09-10 12:33:56

标签: xpath parent nodes siblings

查找其表行必须满足多个条件的xpath节点

搜索那些节点" col_functions"其表行值是" John Wayne"从表@class =" table_list"。

(" col_functions"," col_firstname"" col_lastname是表中的兄弟节点和子节点)

    <table class="table_list">
       <tbody>
        <tr>
           <td class="col_firstname">John</td>
           <td class="col_lastname">Lennon</td>
           <td class="col_functions"></td>
        </tr>
        <tr>
           <td class="col_firstname">John</td>
           <td class="col_lastname">Wayne</td> 
           <td class="col_functions"></td> <=== looking for this node!!
        </tr>
        <tr>
           <td class="col_firstname">Wayne</td>
           <td class="col_lastname">John</td>
           <td class="col_functions"></td>
        </tr>
    </tbody>
  <table>

2 个答案:

答案 0 :(得分:1)

一种选择是检查整个地方的班级名称:

//table[@class="table_list"]//tr[td[@class="col_firstname"] = "John" and td[@class="col_lastname"] = "Wayne"]/td[@class="col_functions"]/text()

这里我们基本上检查table内的所有行,查找姓名为John且姓氏为Wayne的单元格,并将col_functions的单元格作为输出。

答案 1 :(得分:1)

使用兄弟姐妹会是这样的:

//table[@class='table_list']//td[@class='col_firstname'][text()='John']/following-sibling::td[@class='col_lastname'][text=()'Wayne']/following-sibling::td[@class='col_functions']