Simple instructions on how to programmatically download an image from a web page?

Y

Y2KYZFR1

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?
 
B

Bengt Richter

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)
... conn = httplib.HTTPConnection("www.python.org")
... conn.request("GET", "/pics/PythonPoweredSmall.gif")
... r1 = conn.getresponse()
... print r1.status, r1.reason
... data1 = r1.read()
...
200 OK
>>> len(data1) 361
>>> data1[:8] 'GIF89a7\x00'
>>> file('pypowgif.gif','wb').write(data1)
>>> import os, webbrowser
>>> webbrowser.open_new(os.path.abspath('pypowgif.gif'))

or using windows file association, also

You should check errors etc., but the data apparently got through
(not the logo you asked for though ;-)


Regards,
Bengt Richter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top