简体   繁体   中英

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.

尝试这个:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM