Skip to main content
 首页 » 编程设计

python之我应该使用哪个类来抓取图像链接我正在使用 scrapy 和 spider lib

2024年11月01日11lovecherry

这是我写的代码。所有项目都有效接受产品图片链接

product_name = response.css('.product__name::text').extract() 
    product_category = response.css('.product__group::text').extract() 
    product_rarity = response.css('.product__extended-field::text').extract() 
    product_imagelink = response.css('.product__details .product__image .img::attr(src)').extract() 
    product_price = response.css('dd::text').extract() 

请您参考如下方法:

您的问题是不应该有 .在 img 之前,因为它是类型选择器而不是类

product_imagelink = response.css('.product__details .product__image img::attr(src)').extract() 

你可以缩短为

product_imagelink = response.css('.product__image img::attr(src)').extract()