I want to download the picture using the image url using python. How can I download it? I can try all the order which is available on google but no one code is not working on this type of url.
I have tried this code:
import requests # to get image from the web
import shutil # to save it locally
## Set up the image URL and filename
image_url = "https://graph.facebook.com/264520706917918/picture"
filename = image_url.split("/")[-1]
# Open the url image, set stream to True, this will return the stream content.
r = requests.get(image_url, stream = True)
# Check if the image was retrieved successfully
if r.status_code == 200:
# Set decode_content value to True, otherwise the downloaded image file's size will be zero.
r.raw.decode_content = True
# Open a local file with wb ( write binary ) permission.
with open(filename,'wb') as f:
shutil.copyfileobj(r.raw, f)
print('Image sucessfully Downloaded: ',filename)
else:
print('Image Couldn\'t be retreived')
and also these code:
# import wget
# # Set up the image URL
# image_url = "https://graph.facebook.com/264520706917918/picture"
# # Use wget download method to download specified image url.
# image_filename = wget.download(image_url)
# print('Image Successfully Downloaded: ', image_filename)