使用项目字段中的内容重命名Scrapy 0.24中下载的图像,同时避免文件名冲突?

使用项目字段中的内容重命名Scrapy 0.24中下载的图像,同时避免文件名冲突?,第1张

使用项目字段中的内容重命名Scrapy 0.24中下载的图像,同时避免文件名冲突?

pipes.py:

from scrapy.pipelines.images import ImagesPipelinefrom scrapy.http import Requestfrom scrapy.exceptions import DropItemfrom scrapy import logclass MyImagesPipeline(ImagesPipeline):    #Name download version    def file_path(self, request, response=None, info=None):        image_guid = request.meta['model'][0]        log.msg(image_guid, level=log.DEBUG)        return 'full/%s' % (image_guid)    #Name thumbnail version    def thumb_path(self, request, thumb_id, response=None, info=None):        image_guid = thumb_id + request.url.split('/')[-1]        log.msg(image_guid, level=log.DEBUG)        return 'thumbs/%s/%s.jpg' % (thumb_id, image_guid)    def get_media_requests(self, item, info):        yield Request(item['image_urls'][0], meta=item)

您使用的是

settings.py
错误的。您应该使用此:

ITEM_PIPELINES = {'allenheath.pipelines.MyImagesPipeline': 1}

为了使缩略图起作用,请将其添加到

settings.py

IMAGES_THUMBS = {    'small': (50, 50),    'big': (100, 100),}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5508353.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存