Help: How to capture invalid web page from urllib?
richard at bizarsoftware.com.au
Mon Oct 15 06:18:35 CEST 2001
On Monday 15 October 2001 13:56, Paul Lim wrote:
> 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
> 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?
> # If web page is entered, check whether it is a valid web page
> inf = urllib.URLopener.http_error_default(sys.argv)
> except IOError:
> print "Invalid webpage!"
> print "Usage : ./webmap.py http://server-name/path-to-document"
The following should be enough:
... except IOError:
... print "Page doesn't exist"
Page doesn't exist
More information about the Python-list