I am downloading multiple images from a single page and I want to rename them as
count1 = '1' # change to request.url after deprecation
return 'full/%s.jpg' % (count1)
Because file names must be unique within a directory, I would recommend creating a new directory based on the URL from which you've scraped the images.
Then, numbering the images becomes as simple as keeping a counter of how many images you've downloaded so far:
counter = 1 img_sources = sel.xpath("//img/@src").extract() for img_source in img_sources: download_image(img_source, os.path.join(url, "%d.jpg" % (counter))) counter += 1