xxxxxxxxxx
import re
def domain_name(url):
pattern = re.compile(r'(https?://|www\.)?(www\.)?([a-z0-9-]+)(\..+)?')
subbed_url = pattern.sub(r'\3', url)
return subbed_url
xxxxxxxxxx
from urllib.parse import urlparse
domain = urlparse('http://www.example.test/foo/bar').netloc
print(domain) # --> www.example.test
xxxxxxxxxx
from urllib.parse import urlparse
domain = urlparse('https://supermavster.com').netloc
xxxxxxxxxx
url_list = ['https://blog.hubspot.com/marketing/parts-url',
'https://www.almabetter.com/enrollments',
'https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rename.html',
'https://www.programiz.com/python-programming/list']