Scrapy image download how to use custom filename

前端 未结 6 1252
眼角桃花
眼角桃花 2020-11-28 07:27

For my scrapy project I\'m currently using the ImagesPipeline. The downloaded images are stored with a SHA1 hash of their URLs as the file names.

How can I s

6条回答
  •  温柔的废话
    2020-11-28 07:39

    In scrapy 0.12 I solved something like this

    class MyImagesPipeline(ImagesPipeline):
    
        #Name download version
        def image_key(self, url):
            image_guid = url.split('/')[-1]
            return 'full/%s.jpg' % (image_guid)
    
        #Name thumbnail version
        def thumb_key(self, url, thumb_id):
            image_guid = thumb_id + url.split('/')[-1]
            return 'thumbs/%s/%s.jpg' % (thumb_id, image_guid)
    
        def get_media_requests(self, item, info):
            yield Request(item['images'])
    

提交回复
热议问题