Getting text ending with some string in XPath

I have a requirement of getting $7.68 Buy, from below coding using XPath. I need answer in the following format:

//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>

Upvotes: 1

Views: 127

Answers (2)

kjhughes
kjhughes

Reputation: 111541

Given well-formed markup,

<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>

Either of the following XPath expressions will return $7.68 Buy as requested.

XPath 2.0 Solution

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

XPath 1.0 Solution

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

Upvotes: 1

alecxe
alecxe

Reputation: 473863

You have the price in the meta element with itemprop="price" attribute:

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

Upvotes: 1

Related Questions