skip to navigation
skip to content

tldextract 2.0.2

Accurately separate the TLD from the registered domain andsubdomains of a URL, using the Public Suffix List.

tldextract accurately separates the gTLD or ccTLD (generic or country code top-level domain) from the registered domain and subdomains of a URL.

>>> import tldextract
>>> tldextract.extract('')
ExtractResult(subdomain='', domain='cnn', suffix='com')
>>> tldextract.extract('') # United Kingdom
ExtractResult(subdomain='forums', domain='bbc', suffix='')
>>> tldextract.extract('') # Kyrgyzstan
ExtractResult(subdomain='www', domain='worldbank', suffix='')

ExtractResult is a namedtuple, so it’s simple to access the parts you want.

>>> ext = tldextract.extract('')
>>> (ext.subdomain, ext.domain, ext.suffix)
('forums', 'bbc', '')
>>> # rejoin subdomain and domain
>>> '.'.join(ext[:2])
>>> # a common alias
>>> ext.registered_domain
File Type Py Version Uploaded on Size
tldextract-2.0.2-py2.py3-none-any.whl (md5) Python Wheel 2.7 2016-10-16 50KB
tldextract-2.0.2.tar.gz (md5) Source 2016-10-16 49KB