def get_domain(url, tlds):
    url_elements = urlparse(url)[1].split('.')
for i in range(-len(url_elements), 0):
    last_i_elements = url_elements[i:]
How to extract top-level domain name (TLD) from URL