I understand your frustration, and I’m here to help you automate the process of checking the expiry dates of your 1000+ domain names. Manually checking each domain in a browser is indeed time-consuming and inefficient. While the python-whois library is a good starting point, it has limitations, such as rate-limiting, inconsistent WHOIS server responses, and lack of support for some TLDs (top-level domains). To overcome these challenges, I’ll guide you through a more robust solution.
Solution Overview
We will create a Python script that:
- Reads domain names from your Excel file.
- Uses a combination of WHOIS lookups and third-party APIs (if needed) to fetch domain expiry dates.
- Handles rate-limiting and errors gracefully.
- Saves the results back to your Excel file or a new file.
Why whois Library Might Fail
The python-whois library relies on WHOIS servers, which:
- May block frequent requests (rate-limiting).
- Have inconsistent data formats across different TLDs.
- May not respond for certain domains (e.g.,
.co, .io, etc.).
- May require CAPTCHA or other anti-bot measures.
To address these issues, we can use a combination of the whois library and a fallback mechanism, such as a third-party API (e.g., WHOISXMLAPI, DomainTools, etc.), or even web scraping as a last resort. Below, I’ll provide a step-by-step solution using Python.
Step-by-Step Solution
Step 1: Install Required Libraries
You’ll need the following Python libraries:
pandas: To read and write Excel files.
whois: For WHOIS lookups.
requests: For API calls (if using a third-party API).
tqdm: To show a progress bar for long-running tasks.
Install them using pip:
pip install pandas python-whois requests tqdm openpyxl
Step 2: Prepare Your Excel File
Ensure your Excel file (e.g., domains.xlsx) has a column (e.g., Column A) containing the domain names. For example:
| A |
|---|
| example.com |
| google.com |
| mydomain.org |
| ... |
Step 3: Write the Python Script
Below is a Python script that reads the domains from your Excel file, checks their expiry dates using the whois library, and saves the results back to the Excel file. It also includes error handling and a fallback mechanism.
import pandas as pd
import whois
from datetime import datetime
from tqdm import tqdm
import time
# Function to get domain expiry date using WHOIS
def get_expiry_date(domain):
try:
# Perform WHOIS lookup
domain_info = whois.whois(domain)
# Extract expiry date
expiry_date = domain_info.expiration_date
# Handle cases where expiry_date is a list (some WHOIS servers return multiple dates)
if isinstance(expiry_date, list):
expiry_date = expiry_date[0]
# Convert to string if it's a datetime object
if expiry_date:
return expiry_date.strftime('%Y-%m-%d') if isinstance(expiry_date, datetime) else str(expiry_date)
else:
return "Not Found"
except Exception as e:
return f"Error: {str(e)}"
# Function to process domains and update Excel
def process_domains(excel_file, output_file):
# Read the Excel file
df = pd.read_excel(excel_file, engine='openpyxl')
# Ensure the column with domains is named 'Domain' (adjust if needed)
if 'Domain' not in df.columns:
df.columns = ['Domain'] # Rename Column A to 'Domain' if not already named
# Add a new column for expiry dates
df['Expiry Date'] = ''
# Process each domain with a progress bar
for index, row in tqdm(df.iterrows(), total=df.shape[0], desc="Processing domains"):
domain = row['Domain'].strip()
expiry_date = get_expiry_date(domain)
df.at[index, 'Expiry Date'] = expiry_date
# Sleep to avoid rate-limiting (adjust as needed)
time.sleep(1) # Wait 1 second between requests
# Save the updated DataFrame to a new Excel file
df.to_excel(output_file, index=False, engine='openpyxl')
print(f"Results saved to {output_file}")
# Main execution
if __name__ == "__main__":
# Specify your input and output Excel files
input_excel = "domains.xlsx" # Your input file
output_excel = "domains_with_expiry.xlsx" # Output file with results
# Process the domains
process_domains(input_excel, output_excel)
Step 4: Run the Script
- Save the script as
check_domain_expiry.py.
- Place your Excel file (
domains.xlsx) in the same directory as the script.
- Run the script:
python check_domain_expiry.py
- The script will process each domain, fetch its expiry date, and save the results to a new Excel file (
domains_with_expiry.xlsx).
Step 5: Review the Results
The output Excel file will look like this:
| Domain | Expiry Date |
|---|
| example.com | 2024-12-31 |
| google.com | 2025-09-14 |
| mydomain.org | Error: No WHOIS data found |
| ... | ... |
Handling WHOIS Limitations
If the whois library fails for many domains (e.g., due to rate-limiting or unsupported TLDs), you can enhance the solution by using a third-party WHOIS API. Below is an example of how to integrate a WHOIS API (e.g., WHOISXMLAPI) as a fallback.
Step 6: Use a WHOIS API (Optional)
If you have an API key for a service like WHOISXMLAPI, you can modify the script to use it as a fallback. Here’s how:
- Sign up for a WHOIS API service (e.g., WHOISXMLAPI, DomainTools, etc.) and get an API key.
- Modify the
get_expiry_date function to use the API if the WHOIS lookup fails.
Here’s an updated version of the script with WHOISXMLAPI integration:
import pandas as pd
import whois
import requests
from datetime import datetime
from tqdm import tqdm
import time
# Your WHOISXMLAPI key (replace with your actual key)
WHOIS_API_KEY = "your_api_key_here"
WHOIS_API_URL = "https://www.whoisxmlapi.com/whoisserver/WhoisService"
# Function to get domain expiry date using WHOIS
def get_expiry_date(domain):
try:
# Try WHOIS lookup first
domain_info = whois.whois(domain)
expiry_date = domain_info.expiration_date
if isinstance(expiry_date, list):
expiry_date = expiry_date[0]
if expiry_date:
return expiry_date.strftime('%Y-%m-%d') if isinstance(expiry_date, datetime) else str(expiry_date)
else:
return "Not Found"
except Exception as e:
print(f"WHOIS failed for {domain}: {str(e)}. Trying WHOIS API...")
# Fallback to WHOIS API
return get_expiry_date_from_api(domain)
# Function to get expiry date using WHOISXMLAPI
def get_expiry_date_from_api(domain):
try:
# Make API request
params = {
"apiKey": WHOIS_API_KEY,
"domainName": domain,
"outputFormat": "JSON"
}
response = requests.get(WHOIS_API_URL, params=params)
data = response.json()
# Extract expiry date from API response
if "WhoisRecord" in data and "expiresDate" in data["WhoisRecord"]:
expiry_date = data["WhoisRecord"]["expiresDate"]
return expiry_date.split("T")[0] # Extract date part (YYYY-MM-DD)
else:
return "Not Found"
except Exception as e:
return f"API Error: {str(e)}"
# Function to process domains and update Excel
def process_domains(excel_file, output_file):
df = pd.read_excel(excel_file, engine='openpyxl')
if 'Domain' not in df.columns:
df.columns = ['Domain']
df['Expiry Date'] = ''
for index, row in tqdm(df.iterrows(), total=df.shape[0], desc="Processing domains"):
domain = row['Domain'].strip()
expiry_date = get_expiry_date(domain)
df.at[index, 'Expiry Date'] = expiry_date
time.sleep(1) # Avoid rate-limiting
df.to_excel(output_file, index=False, engine='openpyxl')
print(f"Results saved to {output_file}")
# Main execution
if __name__ == "__main__":
input_excel = "domains.xlsx"
output_excel = "domains_with_expiry.xlsx"
process_domains(input_excel, output_excel)
Step 7: Notes on WHOIS APIs
- WHOISXMLAPI: Offers a free tier (limited requests) and paid plans. Check their documentation for details.
- Rate-Limiting: Most APIs have rate limits. Ensure you stay within the limits by adding appropriate delays (
time.sleep()).
- Cost: Be aware of the cost of API requests, especially if you have 1000+ domains.
Step 8: Alternative Approaches
If neither the whois library nor a paid API works for you, consider these alternatives:
-
Web Scraping:
- Use a service like
whois.domaintools.com or whois.icann.org and scrape the expiry date.
- This approach requires libraries like
requests and beautifulsoup4, but be cautious of legal and ethical considerations, as well as anti-bot measures (e.g., CAPTCHAs).
-
Bulk WHOIS Tools:
- Some domain registrars or WHOIS providers offer bulk WHOIS lookup tools. Check if your domain registrar provides such a service.
-
Custom WHOIS Server Queries:
- For specific TLDs, you can query their WHOIS servers directly using the
socket library in Python. This is more advanced and requires knowledge of WHOIS protocols.
Step 9: Best Practices
- Error Handling: The script includes basic error handling, but you may want to log errors to a separate file for debugging.
- Rate-Limiting: Always respect rate limits to avoid being blocked by WHOIS servers or APIs.
- Backup: Keep a backup of your original Excel file before running the script.
- Testing: Test the script with a small subset of domains (e.g., 5–10) before processing all 1000+ domains.
Step 10: Final Thoughts
This solution should help you automate the process of checking domain expiry dates. If you encounter issues with specific domains or TLDs, let me know, and I can help troubleshoot or suggest additional workarounds. Remember that WHOIS data availability and accuracy depend on the domain registrar and TLD, so some domains may not return results due to privacy protections or other restrictions.
If you need further assistance, feel free to ask!