check if string is url python code example
Example 1: check if string is url python
try:
response = requests.get("http://www.avalidurl.com/")
print("URL is valid and exists on the internet")
except requests.ConnectionError as exception:
print("URL does not exist on Internet")
OUTPUT
URL does not exist on Internet
Example 2: python check if string is url
from django.core.validators import URLValidator()
validate = URLValidator()
try:
validate("http://www.avalidurl.com/")
print("String is a valid URL")
except ValidationError as exception:
print("String is not valid URL")