Danny,
I just made some changes, but I still can't get my file saved on my local drive:
here is the new version of the code:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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"
f = urllib.urlopen(url)
# 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()
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
It looks like it is almost doing it but I don't know how to correct so far.
--Matt:)
From: Danny Yoo <[EMAIL PROTECTED]>
To: MATATA EMMANUEL <[EMAIL PROTECTED]>
CC: Tutor@python.org
Subject: Re: [Tutor] Download file from the web and store it locally.
Date: Mon, 22 May 2006 11:29:50 -0700 (PDT)
>
>
>On Mon, 22 May 2006, MATATA EMMANUEL wrote:
>
>>import urllib
>>import sys
>># Get a file-like object from the web and store it locally.
>>url = ""
>>f = urllib.urlopen(url)
>># connect to the remote
>>try:
>> remote = urllib.urlopen(url)
>>except:
>> print "Connot open URL"
>> sys.exit()
>
>Don't do this kind of exception handling: it hides information about
>the exception.
>
>If something bad happens, we want to see something other than
>"Cannot open URL". So instead, let the exception fall through:
>
>###########################################################
>url = ""
>f = urllib.urlopen(url)
>remote = urllib.urlopen(url)
>###########################################################
>
>Or at the very least, modify the exception handler to print out more
>informative error messages other than "An error happened". We can
>use the 'traceback' module in the Standard Library to get us more
>informative error messages.
>
>While you're writing simple programs, I'd recommend avoiding
>exception handlers, just because if something bad happens, we need
>to preserve all the debugging information we can get.
>
>
>
>># Read from the object, storing the page's contents in 's' --> want
>>to
>>download parcels.zip.
>>s = f.read(Parcels.zip)
>
>What is parcels.zip? I don't understand what this is trying to do
>yet.
>
>
>At this point, 'f' is a file whose contents contains the stuff in
>
> http://www.co.rowan.nc.us/enviroservs/downloads.htm
>
>
>I get the feeling you're thinking like a web browser, in the sense
>that you need to first visit the page before downloading the file.
>
>If so, that's not it. *grin*
>
>If the file you're trying to download has a URL like:
>
> http://www.co.rowan.nc.us/enviroservs/Parcels.zip
>
>then there is no reason to have Python visit the downloads.htm page
>first: you can go ahead and grab Parcels.zip first, unless the
>content provider has done something weird to their web server.
>
>
>One other comment:
>
>######
>m = urllib.urlretrieve
>######
>
>This won't fire off. In Python, functions that take no arguments
>still need parens to be called.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor