Automation & scripting
CLI tools, scheduled jobs, filesystem tasks, and glue scripts that save time.
Find All Redirects on a Website in Python
Crawl a website from a starting URL, follow links within the same domain, and detect every HTTP redirect (301, 302, 303, 307, 308) using requests with redirects disabled.
import requests
from urllib.parse import urljoin, urlparse
from collections import deque
def find_redirects(start_url, max_pages=50):
visited = set()
redirects = {}
queue = deque([start_url])
while queue and len(visited) < max_pages:
url = queue.popleft()
if url in visited:
…
How to Monitor Domain Expiration Dates in Python
A Python script that checks domain expiration dates using the python-whois library and warns when a domain is expiring soon.
import whois
from datetime import datetime, timedelta
import time
def check_domain_expiry(domain_name):
"""Check when a domain expires and warn if soon."""
try:
w = whois.whois(domain_name)
expiry = w.expiration_date
# Handle list or single date
if isinstance(expiry, list):
…
How to Validate SSL Certificates for Multiple Domains in Python
A Python utility that checks SSL certificate expiry dates for a list of domains using the standard library ssl and socket modules.
import ssl
import socket
from datetime import datetime
def check_ssl_certificate(hostname: str, port: int = 443) -> dict:
"""Validate SSL certificate for a given hostname."""
context = ssl.create_default_context()
with socket.create_connection((hostname, port), timeout=5) as sock:
with context.wra…
Browse by section
Each section groups closely related Python snippets.
Automation & scripting — Python code examples
What you will find here
This page collects automation & scripting snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.
Samples vs tutorials and challenges
Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.