Accurately separate the TLD from the registered domain and subdomains 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', tld='com')
>>> tldextract.extract('http://forums.bbc.co.uk/') # United Kingdom
ExtractResult(subdomain='forums', domain='bbc', tld='co.uk')
>>> tldextract.extract('http://www.worldbank.org.kg/') # Kyrgyzstan
ExtractResult(subdomain='www', domain='worldbank', tld='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'
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.0.tar.gz
(37.9 kB
view details)
File details
Details for the file tldextract-1.0.tar.gz.
File metadata
- Download URL: tldextract-1.0.tar.gz
- Upload date:
- Size: 37.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1293fe61c661fe7acd62d84a376b9c0ad47f3022e3f4aa8fafe5943067725ae2
|
|
| MD5 |
125776b76dca19db95b9b11e22bfa238
|
|
| BLAKE2b-256 |
93ea6746a941f1b468e5ccb0fcaf3976f7c29e7f67f38958f6daecfbd80096b9
|