Last active
July 25, 2019 21:55
-
-
Save constrict0r/cec36bc93db35f7bec0dd26ee1ec417f to your computer and use it in GitHub Desktop.
Multiple ways to check if an URL is alive.
This file contains hidden or 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
# Using requests. | |
import request | |
request = requests.get(value) | |
if request.status_code == 200: | |
return True | |
return False | |
# Using httplib2. | |
import httplib2 | |
try: | |
http = httplib2.Http() | |
response = http.request(value, 'HEAD') | |
if int(response[0]['status']) == 200: | |
return True | |
except: | |
pass | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment