Alan,

I have changed the code as following but it still printing the contains as something I don't know what it is instead of saving locally! If you click the link in this code, you will see the type of file I would like to be able to download in this script.

import urllib
import sys

# Get a file-like object from the web and store it locally.

url = ""http://www.co.rowan.nc.us/enviroservs/planning_data/countyline.zip">http://www.co.rowan.nc.us/enviroservs/planning_data/countyline.zip"

# connect to the remote
try:
    remote = urllib.urlopen(url)
except:
    print "Connot open URL"
    sys.exit()
# Read from the object, storing the page's contents in 's'.
s = f.read()
m = "D\\Temp\\file"
print remote.info()
m = urllib.urlretrieve
print "Content:"
print s
print "Download Done"
f.close()



From:  "Alan Gauld" <[EMAIL PROTECTED]>
To:  "MATATA EMMANUEL" <[EMAIL PROTECTED]>,<Tutor@python.org>
Subject:  Re: [Tutor] Download file from the web and store it locally.
Date:  Mon, 22 May 2006 20:30:47 +0100
>>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 = ""
>>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.
>
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to