简体   繁体   English

如何从HTML Xpath提取数字

[英]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 : 它返回正确的html路径,它是:

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. 我想使用正则表达式或任何其他方法提取此特定数字2160。 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. 我将其视为字符串,并尝试使用正则表达式获取数字,但这没有用,可能是因为它不是字符串,而是xpath。 Thanks in advance. 提前致谢。

尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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