在XPath中以一些字符串结尾的文本

时间:2015-12-27 15:51:16

标签: html xml xpath

我需要从使用XPath的编码中获得7.68美元的购买。我需要以下列格式回答:

//a[starts-with(@href, 'mailto')]/text()

XML

<button class="price buy id-track-click" data-server-cookie="CAIaIgoeEhwKFmNvbS5tb2phbmcubWluZWNyYWZ0cGUQARgDQgA=" data-uitype="200">
<span>
  <span itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
     <meta content="https://play.google.com/store/apps/details?id=com.mojang.minecraftpe&amp;rdid=com.mojang.minecraftpe&amp;rdot=1&amp;feature=md" itemprop="url">
     <meta content="" itemprop="previewUrl">
     <meta content="" itemprop="offerType">
     <meta content="$7.68" itemprop="price">
     <meta content="" itemprop="description">
     <span itemprop="seller" itemscope="itemscope"  itemtype="http://schema.org/Organization">
        <meta content="Android" itemprop="name">
     </span>
  </span>
 </span>
 <jsl jsl="$x 1;$t t-nH6Xd1T8X0Y;$x 0;">
   <jsl jsl="$x 1;$t t-R7hS--kHwck;$x 0;"> <span jsl="$x 1;"  style="display:none" jsan="5.display"></span> </jsl>
</jsl>
<span>$7.68 Buy</span>    
</button>

2 个答案:

答案 0 :(得分:1)

meta元素的价格为itemprop="price"

//meta[@itemprop="price"]/@content

答案 1 :(得分:1)

鉴于格式正确,

<button class="price buy id-track-click"
        data-server-cookie="CAIaIgoeEhwKFmNvbS5tb2phbmcubWluZWNyYWZ0cGUQARgDQgA="
        data-uitype="200">
  <span>
    <span itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
      <meta content="https://play.google.com/store/apps/details?id=com.mojang.minecraftpe
                     &amp;rdid=com.mojang.minecraftpe&amp;rdot=1&amp;feature=md"
            itemprop="url"/>
      <meta content="" itemprop="previewUrl"/>
      <meta content="" itemprop="offerType"/>
      <meta content="$7.68" itemprop="price"/>
      <meta content="" itemprop="description"/>
      <span itemprop="seller" itemscope="itemscope"
            itemtype="http://schema.org/Organization"/>
      <meta content="Android" itemprop="name"/>
    </span>
  </span>
  <jsl jsl="$x 1;$t t-nH6Xd1T8X0Y;$x 0;">
    <jsl jsl="$x 1;$t t-R7hS--kHwck;$x 0;">
      <span jsl="$x 1;"  style="display:none" jsan="5.display"></span>
    </jsl>
  </jsl>
  <span>$7.68 Buy</span> 
</button>

以下XPath表达式将根据请求返回$7.68 Buy

XPath 2.0解决方案

//span[ends-with(., 'Buy')]/text()

XPath 1.0解决方案

//span['Buy' = substring(., string-length(.) - string-length('Buy') + 1)]/text()