Newbie
Newbie

Reputation: 161

How to extract number from HTML Xpath

Please consider this statement :

hxs.select('//span[@class="product-count"]')

It selects span which is recognized by product-count. It returns correct html path which is :

HtmlXPathSelector xpath='//span[@class="product-count"]' data='<span class="product-count">2160</span>

I want to extract this specific number 2160 using regex or any other method. I treated it as string and tried getting the number using regex but that didn't work, probably because it is not a string and rather an xpath. Thanks in advance.

Upvotes: 0

Views: 158

Answers (1)

gangabass
gangabass

Reputation: 10666

Try this:

number = response.xpath('//span[@class="product-count"]/text()').get()

Upvotes: 1

Related Questions