def top_level ( url , fix_protocol = True ) : ext = tld . get_tld ( url , fix_protocol = fix_protocol ) toplevel = '.' . join ( urlparse ( url ) . netloc . split ( '.' ) [ - 2 : ] ) . split ( ext ) [ 0 ] + ext return toplevel
python how to get domain top ;level
Extract the top level domain from an URL .
def top_level(url, fix_protocol=True):
    """Extract the top level domain from an URL."""
    ext = tld.get_tld(url, fix_protocol=fix_protocol)
    toplevel = '.'.join(urlparse(url).netloc.split('.')[-2:]).split(
        ext)[0] + ext
    return toplevel