The regex should be just:
([0-9\.]+)
Instead of:
^([0-9\.]+)
because the number that you want is not at the beginning of the string
Question
Trying to extract only digits from the following string on website:
<div class="with_basic_sprite" id="m_product_price_div"> 1111 EURO </div>
my xpath for that field is (there are others, working, so I don't include them here) is the following:
s.xpath(".//div[@id='m_product_price_div']/text()").re('^([0-9\.]+)')
and it doesn't work, price fields are empty.
Same with .re('^([\d]+)')
.
tried .extract()
and it pulls both price and currency.
Any hint where I have it wrong with regex?
Solution
The regex should be just:
([0-9\.]+)
Instead of:
^([0-9\.]+)
because the number that you want is not at the beginning of the string
OTHER TIPS
try this:
s.xpath(".//div[@id='m_product_price_div']/text()").re('^\s?([0-9\.]+)')