我正在使用scrapy创建一个数据采集器。为了提取woo-commerce产品图像,我使用以下命令
'img': response.css('figure.woocommerce-product-gallery__image a').attrib['href'],
产品链接:https://royalprint.pk/product/name-print-superhero-sweatshirt-011/
但它在csv中只提取一个img url
我想在一个逗号分隔的列中抓取Woocommerce产品图像。
请帮帮忙。问候
发布于 2020-12-17 20:53:16
试试这个:.getall()
返回一个包含所有结果的列表。
response.css('figure.woocommerce-product-gallery__image a::attr("href")').getall()
输出:
['https://royalprint.pk/wp-content/uploads/2020/12/MaroonSweatshirtWonderWoman.jpg', 'https://royalprint.pk/wp-content/uploads/2020/12/G
reySweatshirtWonderWoman.jpg', 'https://royalprint.pk/wp-content/uploads/2020/12/BlueSweatshirtWonderWoman.jpg', 'https://royalprint.pk/
wp-content/uploads/2020/12/BlackSweatshirtWonderWoman.jpg', 'https://royalprint.pk/wp-content/uploads/2020/12/WhiteSweatshirtWonderWoman
.jpg', 'https://royalprint.pk/wp-content/uploads/2020/12/PinkSweatshirtWonderWoman.jpg']
https://stackoverflow.com/questions/65347641
复制