Python Library: tldextract

Library resources
PyPI https://pypi.org/project/tldextract/
Github https://github.com/john-kurkowski/tldextract
Documentation ---
pip3 install tldextract

Usage

>>> 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')

example

import tldextract
test = 'https://www.amazon.co.uk/Great-Dune-Trilogy-Children-GOLLANCZ-ebook/dp/B07G17V69X/ref=sr_1_1'
output = tldextract.extract(test)
print(output)

outputs:

ExtractResult(subdomain='www', domain='amazon', suffix='co.uk')

Import load time test

import time
start_time = time.time()
import tldextract
run_time = time.time() - start_time
print(f"imported in {run_time}s")

Imports in 0.05s

links

social