Help: How to capture invalid web page from urllib?

Paul Lim paullim at starhub.net.sg
Sun Oct 14 23:56:53 EDT 2001


Hi,

I am a newbie in Python. I hope the guru can advise me on the following

I am trying to open a web page from command line. If the web page is not
valid, I hope to capture the exception and print an error message and
exit.

What I currently have is as below, but I am certain I used the wrong
class because I did not managed to capture the exception (if any) raise.

Could someone teach me how to test the validity of a web page, ie
whether does it exist, can it be open?

Sincerely
Paul

# If web page is entered, check whether it is a valid web page
 try:
    inf = urllib.URLopener.http_error_default(sys.argv[1])
 except IOError:
    print "Invalid webpage!"
    print "Usage : ./webmap.py http://server-name/path-to-document"
    sys.exit()

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20011015/7f3886cc/attachment.html>


More information about the Python-list mailing list