1from urllib.parse import urlparse
2
3domain = urlparse('http://www.example.test/foo/bar').netloc
4print(domain) # --> www.example.test
5
6#To get without the subdomain
7t = urlparse('http://abc.hostname.com/somethings/anything/').netloc
8print ('.'.join(t.split('.')[1:])) # --> hostname.com