August 6, 2008

Python - Downloading Binary Files

Here is a quick example showing how to download and save a binary file (image, zip, etc) to disk using HTTP. This will grab the image file from a website and save it locally:
import urllib

url = ''
f = urllib.urlopen(url)    
fh = open('goldb.png', 'wb')

1 comment:

Marius Gedminas said...

Shorter version:

import urllib
url = '...'
urllib.urlretrieve(url, 'goldb.png')