<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<tt>Hi,</tt><tt></tt>
<p><tt>I am a newbie in Python. I hope the guru can advise me on the following</tt><tt></tt>
<p><tt>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.</tt><tt></tt>
<p><tt>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.</tt><tt></tt>
<p><tt>Could someone teach me how to test the validity of a web page, ie
whether does it exist, can it be open?</tt><tt></tt>
<p><tt>Sincerely</tt>
<br><tt>Paul</tt><tt></tt>
<p><tt># If web page is entered, check whether it is a valid web page</tt>
<br><tt> try:</tt>
<br><tt>    inf = urllib.URLopener.http_error_default(sys.argv[1])</tt>
<br><tt> except IOError:</tt>
<br><tt>    print "Invalid webpage!"</tt>
<br><tt>    print "Usage : ./webmap.py <A HREF="http://server-name/path-to-document">http://server-name/path-to-document</A>"</tt>
<br><tt>    sys.exit()</tt>
<br><tt></tt> </html>