Last modified: Nov 04, 2023 By Alexander Williams

Python Get Domain Expiration Date Example

Example: Get Domain Expiration Date Using Python


import whois

# Define the domain name you want to check
domain_name = "example.com"

# Query WHOIS information for the domain
domain_info = whois.whois(domain_name)

# Check if the expiration date is available
if domain_info.status:
    expiration_date = domain_info.expiration_date
    if isinstance(expiration_date, list):
        expiration_date = expiration_date[0]
    print(f"The domain '{domain_name}' expires on {expiration_date}")
else:
    print(f"Unable to retrieve WHOIS information for '{domain_name}'")

Output:


The domain 'example.com' expires on 2030-08-13 04:00:00