Home > Software design >  Рow to get multiple values at the same timeusing xPath
Рow to get multiple values at the same timeusing xPath

Time:10-01

I have a list of prices that I need to get. They are all not in li.They are in div.And I have this situation:

<div class="col search_price discounted responsive_secondrow">
  <span style="color: #888888;"><strike>30 758₴</strike></span><br>
   26 973₴                    
</div>
<div class="col search_price_discount_combined responsive_secondrow" data-price-final="644900">
<div class="col search_price  responsive_secondrow">
         6 449₴                    
</div>

I need to write such xPath what I could get at the same time 26 973₴ and 6 449₴
How can I do that?

CodePudding user response:

To select the first non-empty text() node of an element, you can use this XPath expression:

./div/text()[normalize-space()][1]

This expression relates to the context node of your example.
But, of course, to get all results, you have to iterate over all result nodes.


To make the expression a little bit more distinctive, you could use

//div[contains(@class,'discount')]/text()[normalize-space()][1]
  • Related