0

I'm using scrapy to do a project. I got the image name and image url in html, how can I name this image with that name instead of the hash name?

I got this url: http://a3.mzstatic.com/us/r1000/104/Purple/v4/55/35/20/55352022-0aba-260b-76ed-314eacd8c1fc/mzm.zqqzrdix.175x175-75.jpg and it's name: iBook I want my scrapy to download this picture and rename it with iBook.

Flagbug
  • 2,093
  • 3
  • 24
  • 47
Adoni
  • 1
  • 1
  • 1
  • Could you post your spider code and the url you're crawling (I'm guessing it's the Apple website) so that we take a look at what you've got so far? – Talvalin Jan 06 '13 at 04:57
  • Possible duplicate of [Scrapy: customize Image pipeline with renaming defualt image name](https://stackoverflow.com/questions/18081997/scrapy-customize-image-pipeline-with-renaming-defualt-image-name) – Gallaecio May 27 '19 at 06:58

1 Answers1

6

You have to use the Images pipeline and something like this

class MyImagesPipeline(ImagesPipeline):

    def image_key(self, url):
        image_guid = url.split('/')[-1]
        return 'full/%s' % (image_guid)

It will use the original image name. For custom filename use something like

return 'ibook.jpg' But it will overwrite all the images with same file. be careful

get some more ideas from this Scrapy image download how to use custom filename

Community
  • 1
  • 1
Mirage
  • 30,868
  • 62
  • 166
  • 261