Accurately separate the TLD from the registered domain andsubdomains of a URL, using the Public Suffix List.
Project description
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'
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-2.0.2.tar.gz
(50.4 kB
view hashes)
Built Distribution
Close
Hashes for tldextract-2.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89934e9db5ce943cf3a0ec65b28e45821f53b88ed04c81829954d0062daba2d5 |
|
MD5 | a59022d979b107f2d618f42f1a681802 |
|
BLAKE2b-256 | 704e08c9a650e2a67b1bb27137be0aeb879755984ca6efb58d26e5c1af42ddce |