Check URL --> Simply?

JS joesalt at ireland.com
Wed Aug 15 10:33:59 EDT 2001


One question regarding handling directories from the example below...

>>> checkURL('http://www.slashdot.org')
1
>>> checkURL('http://www.slashdot.org/notadirectory')
1

In the second example, the directory doesn't exist, yet I am returned
1? Is there a way to handle this?

As always, Thanks!


Alex <new_name at mit.edu> wrote in message news:<etd3d6uf05b.fsf at lola-granola.mit.edu>...
> import urllib
> 
> def checkURL(url):
>     try: urllib.urlopen(url)
>     except IOError: return 0
>     return 1
> 
> if __name__ == '__main__':
>     assert checkURL('http://slashdot.org')
>     assert not checkURL('http://foo')
>     
> HTH.
> Alex.



More information about the Python-list mailing list