I would like to extract number/float value from this code using Xidel:
<p class="price">
<span class="woocommerce-Price-amount amount">
<bdi>
304.00
<span class="woocommerce-Price-currencySymbol">
€
</span>
</bdi>
</span>
</p>
I am trying the following command:
xidel -s '<p class="price"><span class="woocommerce-Price-amount amount"><bdi>304.00 <span class="woocommerce-Price-currencySymbol">€</span></bdi></span></p>' -e "//p[@class='price']/translate(normalize-space(substring-before(., '€')),' ','')"
The translate command should replace space, but it’s not working, in the output I still see one space after number "304.00_".
2
Answers
Try changing the xpath expression to
or
or use
tokenize()
The output should be
You’re going to have to process the no-break space separately with one of the following queries:
You can’t use
normalize-space()
, because…https://www.w3.org/TR/xpath-functions-31/#func-normalize-space:
…it processes spaces, tabs, carriage returns and line feeds, but not no-break spaces:
Btw, an alternative to get the price on that website: