pub-3785248829033902 | Python: Download Image from url | - Big data with Python

| Python: Download Image from url |

If you want to download images from the internet, assuming that you already have the list of image urls, then the best way is using python. Most of the articles on the internet provide a code to download images with a predefined image name, and do not allow to preserve the original image name. 



These codes do not allow the users to download large number of images as the images cannot be named dynamically. 

The best way to learn new things is to take a practical approach of the things you want to learn. Here is a fragment of code that demonstrates the use of the download statement in Python:

Æ’ python command

import random
import urllib.request
def download_web_image(url):
     name = random.randrange(1, 1000)
     full_name = str(name) + '.jpg'
     urllib.request.urlretrieve(url, full_name)
#'my_image.jpg'
download_web_image('http://www.birdsofeden.co.za/userfiles/article/Largepics/hummingbird11.jpg')

output

try it yourself and see the image!



Previous
Next Post »