Wednesday, September 23, 2009

python - copy images (or any file) from the web to local machine

# copy images off of the web to your local machine
# (this should work for any files off the web...not just images)

import urllib
import os

url_of_file = ""
local_file = "local_copy.jpg"

# retrieve from web and put in local_file
urllib.urlretrieve(url_of_file, local_file)

# now proof that the file was copied
# just listing all files in working directory
print os.listdir('.')

No comments:

Post a Comment