-
-
Save Intelrunner/46d0885d00e8826c89c4fad7afc3930b to your computer and use it in GitHub Desktop.
To check whether a given url is up or not
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
from six.moves import urllib | |
import requests | |
def url_is_alive(url): | |
""" | |
Checks that a given URL is reachable. | |
:param url: A URL | |
:rtype: bool | |
""" | |
request = urllib.request.Request(url) | |
request.get_method = lambda: 'HEAD' | |
# print(request.head(url).status_code) | |
try: | |
urllib.request.urlopen(request,timeout=1) | |
return True | |
except : | |
return False | |
if __name__ == '__main__': | |
status = url_is_alive(url) | |
print(status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment