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-1.7.4.tar.gz
(63.8 kB
view details)
File details
Details for the file tldextract-1.7.4.tar.gz.
File metadata
- Download URL: tldextract-1.7.4.tar.gz
- Upload date:
- Size: 63.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5d6675d84fab0d8098f84ed90720a525f664538f6ea370af49b32eb2c67240a
|
|
| MD5 |
312ffe98aaca472b5dcd173251ff19d5
|
|
| BLAKE2b-256 |
6faf756027aa3f7d14f6d1fcf2f0938be14dc6f9b5d0f53a92ee558787f53afb
|