Last active
June 24, 2022 16:25
-
-
Save jaydeepkarale/be2168fda3a563d0033af8c6840a77eb to your computer and use it in GitHub Desktop.
Validate URL Snippets
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
from aiohttp import web | |
from http import HTTPStatus | |
import validators | |
import requests | |
def validate_url_format(longurl: str): | |
"""This function returns True if the longurl is in a valid format""" | |
return validators.url(longurl) | |
def validate_url(longurl: str): | |
"""This function retruns True if the longurl is a valid web address""" | |
try: | |
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0'} | |
response = requests.get(longurl, headers=headers) | |
return response.status_code == HTTPStatus.OK | |
except Exception as ex: | |
print(ex) | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment