Simple instructions on how to programmatically download an image from a web page?
bokr at oz.net
Thu Nov 27 18:22:41 CET 2003
On 26 Nov 2003 23:00:54 -0800, jarrodhroberson at yahoo.com (Y2KYZFR1) wrote:
>I have search the group and not found a working example on how to
>simply download a .gif from a url.
>something as simple as
>http://groups.google.com/images/threadview_logo.gif should be pretty
>easy, guess not?
>I don't need to know about using a browser, I need to know how to do
>it programmatically from Python.
>Anyone know how to get it done?
I just tried this interactively some example lines from httplib
(the if 1: was just to execute the indented lines in one go)
>>> import httplib
>>> if 1:
... conn = httplib.HTTPConnection("www.python.org")
... conn.request("GET", "/pics/PythonPoweredSmall.gif")
... r1 = conn.getresponse()
... print r1.status, r1.reason
... data1 = r1.read()
>>> import os, webbrowser
or using windows file association, also
You should check errors etc., but the data apparently got through
(not the logo you asked for though ;-)
More information about the Python-list