For parsing the domain of a URL in Python 3, you can use:
from urllib.parse import urlparse
domain = urlparse('http://www.example.test/foo/bar').netloc
print(domain) # --> www.example.test
However, for reliably parsing the top-level domain (example.test in this example), you need to install a specialized library (e.g., tldextract).