Newbie: How to download a JPG file from the internet....?

Dietmar Lang dietmar at nospam.wohnheim.fh-wedel.de
Mon Sep 17 22:49:58 CEST 2001


Hi!

>     Can anyone tell me how to download an image from a web site?
> An example:
><IMG SRC="./images/getme.jpg"> that is located at www.somewhere.org
> 
>     I have already found the urllib module and have used the urlopen
> function to create a string from a web page,  but I don't know how to
> proceed from here.  I can isolate the string -  <IMG
> SRC="./images/getme.jpg">, but then what?  I would like to eventually write
> it to a file on my local drive.  Any information will be greatly
> appreciated.  Thank you for your time.

Well, I did something like this a couple days ago:

## begin code

import urllib

url = 'http://www.somewhere.org/images/getme.jpg'

filename = 'getme.jpg' # coerce the name from your string

image = urllib.URLopener()
image.retrieve(url, filename())

## end code

Something in that order will do the trick. At least it does for me every
day, downloading the latest comic strips from the web. ;)

Kudos, Dietmar

-- 
To mail me, remove "nospam.".



More information about the Python-list mailing list