Check URL --> Simply?

Andy McKay andym at ActiveState.com
Wed Aug 15 12:22:35 EDT 2001


Just check the headers, this means you dont get the document, saving 
bandwith and solving the 404 file problem (assuming the set the right 
headers)

from httplib import HTTP
from urlparse import urlparse

def checkURL(url):
     p = urlparse(url)
     h = HTTP(p[1])
     h.putrequest('HEAD', p[2])
     h.endheaders()
     if h.getreply()[0] == 200: return 1
     else: return 0

if __name__ == '__main__':
     assert checkURL('http://slashdot.org')
     assert not checkURL('http://slashdot.org/notadirectory')

-- 
   Andy McKay





More information about the Python-list mailing list