Trouble renaming downloaded images in a customized manner through pipelines

前端 未结 1 909
终归单人心
终归单人心 2021-01-26 01:58

I\'ve created a script using python\'s scrapy module to download and rename movie images from a torrent site and store them in a folder within scrapy project. When I run my scri

相关标签:
1条回答
  • 2021-01-26 02:20

    Override get_media_requests() and add the data you need to the request. Then grab that data from the request in file_path().

    For example:

    class YifySpiderPipeline(ImagesPipeline):
    
        def get_media_requests(self, item, info):
            # Here we add the whole item, but you can add only a single field too.
            return [Request(x, meta={'item': item) for x in item.get(self.images_urls_field, [])]
    
        def file_path(self, request, response=None, info=None):
            item = request.meta.get('item')
            movie = item['movie']
            # Construct the filename.
            return image_name
    
    0 讨论(0)
提交回复
热议问题