Python Scrapy选择器返回整个xpath,而不是值
我正在努力刮: 我正试图通过以下方式获取产品的价格价值:Python Scrapy选择器返回整个xpath,而不是值,python,xpath,scrapy,Python,Xpath,Scrapy,我正在努力刮: 我正试图通过以下方式获取产品的价格价值: price=(response.xpath('//span[@class="product-price--regular "]/text()').get) print("price"+str(price)) 这将返回整个路径,而不是其中的值: price<bound method SelectorList.get of [<Selector xpath='//span[@class="product-price--re
price=(response.xpath('//span[@class="product-price--regular "]/text()').get)
print("price"+str(price))
这将返回整个路径,而不是其中的值:
price<bound method SelectorList.get of [<Selector xpath='//span[@class="product-price--regular "]/text()' data='$69.50'>, <Selector xpath='//span[@class="product-price--regular "]/text()' data='$69.50'>]>
价格
我只需要数值。调用get(),而不是打印函数本身 试试这个
(Pdb) response.xpath('//span[@class="product-price--regular "]/text()').get()
'$59.50'
不,你不是在打电话。get后面的括号不是函数调用的括号,它起作用了。但是我的和你的有什么不同呢?快!这样就错过了圆括号调用
get()
。另外,避免多余的圆括号。