Accurately separates a URL's subdomain, domain, and public suffix, using the Public Suffix List (PSL). By default, this includes the public ICANN TLDs and their exceptions. You can optionally support the Public Suffix List's private domains as well.
Project description
tldextract
accurately separates a URL's subdomain, domain, and public suffix,
using the Public Suffix List (PSL).
>>> 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tldextract-3.2.1.tar.gz
(104.4 kB
view hashes)
Built Distribution
tldextract-3.2.1-py3-none-any.whl
(87.8 kB
view hashes)
Close
Hashes for tldextract-3.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d57830dbf3806c1ecb973099f75124f45eea7432817e78e6c6ddad0beef185d |
|
MD5 | 329d1c2b5114b98c3f6135d204773154 |
|
BLAKE2b-256 | 3e35a6de9f0ec87bb582f7212121807eeaf57d5abe83a2caff99ac538f6efdbd |