import tldextract
def check_url(url):
response = requests.get(url)
if response.status_code == 200:
print(f"{url} is LIVE")
return True
else:
print(f"{url} is DEAD")
return False
def find_new_url(url):
if url.startswith("http"):
extract = tldextract.extract(url)
domain = f"{extract.domain}.{extract.suffix}"
else:
domain = url
v1 = f"https://{domain}"
if check_url(v1):
return v1
else:
v2 = f"https://www.{domain}"
if check_url(v2):
return v2
else:
v3 = f"http://{domain}"
if check_url(v3):
return v3
else:
v4 = f"http://www.{domain}"
if check_url(v4):
return v4
else:
return None
Find working URL with Python
from URL or domain