문제

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?

도움이 되었습니까?

해결책

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

다른 팁

try this:

s.xpath(".//div[@id='m_product_price_div']/text()").re('^\s?([0-9\.]+)')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top