Skip to content Skip to sidebar Skip to footer

Grab An Image Via The Web And Save It With Python

I want to be able to download an image (to my computer or to a web server) resize it, and upload it to S3. The piece concerned here is: What would be a recommended way to do the do

Solution 1:

urllib (simple but a bit rough) and urllib2 (powerful but a bit more complicated) are the recommended standard library modules for grabbing data from a URL (either to memory or to disk). For simple-enough needs, x=urllib.urlopen(theurl) will give you an object that lets you access the response headers (e.g. to find out the image's content-type) and data (as x.read()); urllib2 works similarly but lets you control proxying, user agent, coockies, https, authentication, etc, etc, much more than simple urllib does.

Solution 2:

Consider:

importurllibf= urllib.urlopen(url_of_image)
image = f.read()

http://docs.python.org/library/urllib.html

Solution 3:

You could always have a look at hand.

If I remember correctly, it was written to grab cartoons from sites that don't have feeds

This project seems to have died, so it's no longer an option. Anyway, using urllib seems to be what you're looking for.

Post a Comment for "Grab An Image Via The Web And Save It With Python"