How to download scrapy images in to a dynamic folder?

后端 未结 2 754
小蘑菇
小蘑菇 2020-12-21 05:55

I am able to download images through scrapy in to the \"Full\" folder but I need to make the name of the destination folder dynamic, like full/session_id, every

2条回答
  •  被撕碎了的回忆
    2020-12-21 06:37

    here is the answer stackoverflow.com

    class StoreImgPipeline(ImagesPipeline):
        def file_path(self, request, response=None, info=None):
            image_guid = hashlib.sha1(to_bytes(request.url)).hexdigest()
            return 'realty-sc/%s/%s/%s/%s.jpg' % (YEAR, image_guid[:2], image_guid[2:4], image_guid)
    

提交回复
热议问题