如何从 HTML Xpath 中提取数字



请考虑以下声明:

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

它选择由产品计数识别的范围。它返回正确的 html 路径,即:

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

我想使用正则表达式或任何其他方法提取这个特定的数字 2160。我将其视为字符串并尝试使用正则表达式获取数字,但这不起作用,可能是因为它不是字符串,而是 xpath。提前谢谢。

试试这个:

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

最新更新