Xpath索引无法正常工作

时间:2017-05-02 00:58:10

标签: xpath

我需要该类和父级的第三个图像。这些xpath似乎都没有效果。

xpath=(//div[@class='itemTileV5'])//img[@class='dealItem']/@src[3]
xpath=(//div[@class='itemTileV5']//img[@class='dealItem'])/@src[3]
xpath=(//div[@class='itemTileV5']//img[@class='dealItem']/@src)[3]

注意我移动括号并且它始终是无效路径。如果没有括号,它也无法工作。 请帮忙。

<div class="itemTileV5">
 <div class="top">
  <a href="/Grocery_deals/p_pepperidge-farm-goldfish-variety-pack-bold-mix-29-4-ounce">
   <img class="Item" src="https://img.google.com/ai/184x184/dealimage/1493649114.jpg" alt="Pepperidge Farm">
  </a>
 </div>
</div>

1 个答案:

答案 0 :(得分:0)

All three of your expressions are valid in all versions of XPath. If you're getting an error, please tell us what it is, and what XPath processor generated it.

The first two expressions aren't useful, because @src[3] selects the third attribute called "src" and there can only be one attribute with a given name.

Your informal requirement "the third image with that class and parent" seems to translate to (//div[@class='itemTileV5']/img[@class='dealItem'])[3]/@src