Skip to content

Instantly share code, notes, and snippets.

@asadamatic
Created March 5, 2020 05:05
Show Gist options
  • Save asadamatic/5b70be24d3975329045ebc31dc755ffb to your computer and use it in GitHub Desktop.
Save asadamatic/5b70be24d3975329045ebc31dc755ffb to your computer and use it in GitHub Desktop.
Code to donwload images using requests library in python.
import requests
import time
imageUrl = 'https://images.unsplash.com/photo-1558981396-5fcf84bdf14d'
image = requests.get(imageUrl)
imageBytes = image.content
fileName = imageUrl.split('/')[3] + '.png' #getting photo name from the url
with open(fileName , 'wb') as file: #Openning a new file in 'Write Bytes' mode
file.write(imageBytes)
print('Finished downloading image :)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment