Python experiment to get an image from a web page and save it to an image file. Updated code to work with both Python versions ...
Retrieve and save an image from a web page
'''urlretrieve_image1.py
retrieve and save an image from a web page
using ...
urlretrieve(url[, filename[, reporthook[, data]]])
tested with Python27 and Python33 by vegaseat
'''
try:
# Python2
from urllib import urlretrieve
except ImportError:
# Python3
from urllib.request import urlretrieve
# find yourself a picture on an internet web page you like
# (right click on the picture, look under properties and copy the address)
url = "http://www.google.com/intl/en/images/logo.gif"
filename = "logo.gif"
# retrieve the image from the url and save it to file
urlretrieve(url, filename)
print("image saved as %s" % filename)
# try to show the saved image file ...
import webbrowser
webbrowser.open(filename)
snippsat 661 Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.