Skip to content

Instantly share code, notes, and snippets.

@asadamatic
Created March 5, 2020 05:09
Show Gist options
  • Save asadamatic/9c6007092fb514f9e4d9d72ab916963e to your computer and use it in GitHub Desktop.
Save asadamatic/9c6007092fb514f9e4d9d72ab916963e to your computer and use it in GitHub Desktop.
Code to download multiple images using requests library in python.
import requests
import time
imageUrls = ['https://images.unsplash.com/photo-1558981396-5fcf84bdf14d',
'https://images.unsplash.com/photo-1583314059352-663691cfa23f',
'https://images.unsplash.com/photo-1583314238585-21664bba94ab',
'https://images.unsplash.com/photo-1583317094917-8aac805fed5a' ,
'https://images.unsplash.com/photo-1583307266943-e0055bb40037' ]
startTime = time.perf_counter()
for url in imageUrls:
imageName = url.split('/')[3] + '.png'
with open(imageName , 'wb') as image: #Opening file in 'Write Bytes' mode
imageInBytes = requests.get(url).content
image.write(imageInBytes) #Writing image bytes onto the opened file
finishTime = time.perf_counter()
executionTime = round((finishTime - startTime) , 2)
print('Program finished in {} seconds.'.format(executionTime))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment