skip to navigation
skip to content

Not Logged In

tldextract 1.3.1

Accurately separate the TLD from the registered domain and subdomains 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('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.domain
'bbc'
>>> '.'.join(ext[:2]) # rejoin subdomain and domain
'forums.bbc'
 
File Type Py Version Uploaded on Size
tldextract-1.3.1.tar.gz (md5) Source 2013-12-17 56KB
  • Downloads (All Versions):
  • 218 downloads in the last day
  • 1246 downloads in the last week
  • 5687 downloads in the last month