skip to navigation
skip to content

tldextract 2.0.3

Accurately separate the TLD from the registered domain and subdomains of a URL, using the Public Suffix List. Bydefault, this includes the public ICANN TLDs and theirexceptions. You can optionally support the Public SuffixList's private domains as well.

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('http://forums.news.cnn.com/')
ExtractResult(subdomain='forums.news', domain='cnn', suffix='com')
>>> tldextract.extract('http://forums.bbc.co.uk/') # United Kingdom
ExtractResult(subdomain='forums', domain='bbc', suffix='co.uk')
>>> tldextract.extract('http://www.worldbank.org.kg/') # Kyrgyzstan
ExtractResult(subdomain='www', domain='worldbank', suffix='org.kg')

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

>>> ext = tldextract.extract('http://forums.bbc.co.uk')
>>> (ext.subdomain, ext.domain, ext.suffix)
('forums', 'bbc', 'co.uk')
>>> # rejoin subdomain and domain
>>> '.'.join(ext[:2])
'forums.bbc'
>>> # a common alias
>>> ext.registered_domain
'bbc.co.uk'

By default, this package supports the public ICANN TLDs and their exceptions. You can optionally support the Public Suffix List’s private domains as well.

 
File Type Py Version Uploaded on Size
tldextract-2.0.3-py2.py3-none-any.whl (md5) Python Wheel 2.7 2017-05-20 51KB
tldextract-2.0.3.tar.gz (md5) Source 2017-05-20 49KB