Grab An Image Via The Web And Save It With Python
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:
import urllib
f = urllib.urlopen(url_of_image)
image = f.read()
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"