刮擦选择器返回整个 xpath 而不是值



我正在尝试抓取: https://www.jny.com/products/cuff-sleeve-v-neck-top-floral-spice-combo

我正在尝试使用以下方法刮除产品中提到的价格值:

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'

最新更新