download all mib files from a web page

Scott David Daniels Scott.Daniels at Acm.Org
Wed May 27 15:37:05 EDT 2009


powah wrote:
> ...
> I fixed one error, now if the filename is misspelled, how to ignore
> the error and continue?

You really should go through the tutorial.  It will explain this and
other important things well.  But, since I'm feeling generous:

Replace this:
>     u=urllib2.urlopen(link)
>     p=u.read()
>     open(filename,"w").write(p)
with this:
       try:
           u = urllib2.urlopen(link)
           p = u.read()
       except urllib2.HTTPError:
           pass
       else:
           dest = open(filename, "w")
           dest.write(p)
           dest.close()

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list