0

I want to store an image in a different folder, the folder name is item['title'].
Please look into below code, but it doesn't work.

  def image_key(self, url,item):
                image_guid = hashlib.sha1(url).hexdigest()
                return '%s/full/%s.jpg' % (item['title'],image_guid)
        def get_media_requests(self, item, info):
                for image_url in item['image_urls']:
                        yield Request(image_url,meta={'id':item['title']})
        def item_completed(self, results, item, info):
                image_paths = [x['path'] for ok, x in results if ok]
                if not image_paths:
                        raise DropItem("item contains no images")
                item['image_paths'] = image_paths
                return item

Any ideas?

matthias_h
  • 11,356
  • 9
  • 22
  • 40
  • Have a look at my answer to http://stackoverflow.com/questions/18081997/scrapy-customize-image-pipeline-with-renaming-deafult-image-name . It requires overriding `get_media_requests()` to add `meta` in Requests, and `get_images()` to use more than the image URL to generate the name/path of the final image – paul trmbrth Aug 12 '13 at 14:00
  • Thanks,I have realized by the http://stackoverflow.com/questions/18081997/scrapy-customize-image-pipeline-with-renaming-deafult-image-name – user2670925 Dec 04 '13 at 15:07

0 Answers0