Xpath - 在提取值时需要帮助

时间:2014-09-12 11:38:59

标签: xml xpath

对于以下HTML内容,有人可以帮我提取价格(价格2),该价格恰好在节点标签之后,并且具有已检查的属性=" true"。 示例HTML内容:

<tbody>
<tr>
<td>
<label class="left">
<input type="radio" data-max-per-order="12" data-out-of-stock="0" data-purchasable="1" data-product-id="29391" data-product-option-id="24501" name="type" class="product-option" id="product_option_radio_for-24501" />3 doses</label>
</td>
<td id="per_pound_for_24501" class="right">
<span class="competitor">
$10.65
</span>
</td>
<td class="ships-free"> </td>
<td data-price="price1" id="price_for_24501" class="right">$Price1</td>
</tr>
<tr>
<td>
<label class="left">
<input type="radio" data-max-per-order="12" data-out-of-stock="0" data-purchasable="1" data-product-id="29391" data-product-option-id="24688" name="type" class="product-option" id="product_option_radio_for-24688" checked="true" />Some Text</label>
</td>
<td id="per_pound_for_24688" class="right">
<span class="competitor">
$8.99
</span>
</td>
<td class="ships-free"> <div>SHIPS <br /> FREE!</div></td>
<td data-price="Price2" id="price_for_24688" class="right">$Price2</td>
</tr>
</tbody>

1 个答案:

答案 0 :(得分:2)

我相信有许多不同的XPath可以做同样的事情,例如:

//tr[
      td//input[@checked='true'] 
    ]
/td[@data-price]