[Tutor] Download file from the web and store it locally.

Alan Gauld alan.gauld at freenet.co.uk
Mon May 22 21:30:47 CEST 2006


> I need help on this script. I'm trying to download zip file from the 
> web and store it to my local drive: It is printing info, but doesn't 
> download any thing.

Looks like you are a wee bit confused on what you are trying to do.

> import urllib
> import sys
> # Get a file-like object from the web and store it locally.
> url = "http://www.co.rowan.nc.us/enviroservs/downloads.htm"
> f = urllib.urlopen(url)

Here you open a link to the url

> # connect to the remote
> try:
>    remote = urllib.urlopen(url)

and here you open another to the same url - do you need 2?

> # Read from the object, storing the page's contents in 's' --> want 
> to download parcels.zip.
> s = f.read(Parcels.zip)

But now you are trying to read from the url, but you pass a variable 
name
(Parcels.zip) which is probably not recognised? If it was a filename 
it would
have quotres around it. But read() doesn't take filenames so thatsd 
not
right either.

read() will read the p[age contents of your url back as a string.

If the page has a link to Parcels.zip you will have to find it and 
extract
the url for the file - you will probably find it esier to use your 
browser
to do this, with View->source if necessary

Then use the actual url to the zip file instead of the html file 
above.

Assuming I've understood what you are trying to do correctly.

HTH,

Alan G. 




More information about the Tutor mailing list