Python 如何从HTMLXPath中提取数字 请考虑这个陈述: hxs.select('//span[@class="product-count"]')
它选择由产品计数识别的范围。它返回正确的html路径,即:Python 如何从HTMLXPath中提取数字 请考虑这个陈述: hxs.select('//span[@class="product-count"]'),python,scrapy,pycharm,Python,Scrapy,Pycharm,它选择由产品计数识别的范围。它返回正确的html路径,即: HtmlXPathSelector xpath='//span[@class="product-count"]' data='<span class="product-count">2160</span> htmlxpath选择器xpath='//span[@class=“product count”]'data='2160 我想使用正则表达式或任何其他方法提取这个特定的数字2160。我将其视为字符串,并尝试
HtmlXPathSelector xpath='//span[@class="product-count"]' data='<span class="product-count">2160</span>
htmlxpath选择器xpath='//span[@class=“product count”]'data='2160
我想使用正则表达式或任何其他方法提取这个特定的数字2160。我将其视为字符串,并尝试使用正则表达式获取数字,但没有成功,可能是因为它不是字符串,而是xpath。
提前感谢。试试这个:
number = response.xpath('//span[@class="product-count"]/text()').get()
使用response.css('.product count::text').get()
@abdusco尝试了此打印(response.css('.product count::text').get())。它表示不尝试在XPath选择器之后添加/text()
,然后添加hxs.select('//span[@class=“product count”]/text())
scrapy使用extract()
从标记中获取文本。.get()
和现在推荐使用.getall()
。