Created
August 24, 2015 05:52
-
-
Save alamsal/d9bec80f44e0e08ecd25 to your computer and use it in GitHub Desktop.
Check if URL is dead or live
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib | |
from urlparse import urlparse | |
def checkUrl(url): | |
p = urlparse(url) | |
conn = httplib.HTTPConnection(p.netloc) | |
conn.request('HEAD', p.path) | |
resp = conn.getresponse() | |
return resp.status < 400 | |
if __name__ == '__main__': | |
print checkUrl('http://www.stackoverflow.com') # True | |
print checkUrl('http://stackoverflow.com/notarealpage.html') # False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment