Python get domain name from URL
------------------------------------------------------------
input_string = 'https://mail.google.com/mail/u/0/'
Domain_name = ""
x = input_string.split("/")
if(x[0] == "https:" or x[0] == "http:"):
x = x[2].split(".")
else:
x = x[0].split(".")
if (len(x) == 2):
Domain_name = x[0]
else:
Domain_name = x[1]
print("The Domain Name is ", Domain_name)
------------------------------------------------
Python get domain from URL
from urllib.parse import urlparse
domain = urlparse('http://app.example.test/foo/bar').netloc
print(domain) # --> www.example.test--------------------------------------------------
إرسال تعليق