Reference library

Automation & scripting

CLI tools, scheduled jobs, filesystem tasks, and glue scripts that save time.

6 matches
Automation & scripting medium

Create a Python Script That Detects Website Technology Stack Automatically

This script sends an HTTP request to a URL and inspects headers and HTML content to identify technologies like servers, frameworks, and JavaScript libraries.

requests web scraping tech stack
Python
import requests
from re import search

def detect_tech_stack(url):
    tech_stack = []
    try:
        response = requests.get(url, timeout=5, headers={'User-Agent': 'Mozilla/5.0'})
        headers = response.headers
        html = response.text.lower() if response.text else ''

        # Check server header
        …
43 0 Open
Automation & scripting medium

Extract All Links from Any Website in Python

Scrape a webpage and extract all absolute HTTP/HTTPS links using requests and regex.

web-scraping links requests
Python
import requests
import re
from urllib.parse import urljoin

def extract_links(url):
    try:
        response = requests.get(url)
        response.raise_for_status()
        html = response.text
        # Find all href attributes in anchor tags
        pattern = r'href=["\'](.*?)["\']'
        raw_links = re.findall(p…
43 0 Open
Automation & scripting medium

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.

redirects crawling requests
Python
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:
      …
38 0 Open
Automation & scripting medium

Find Broken Image References Across a Website in Python

Crawl internal pages of a website, collect all image source URLs, then check each with HEAD requests to report any that return HTTP 4xx or connection errors.

web scraping crawling broken links
Python
import requests
from urllib.parse import urljoin, urlparse
from bs4 import BeautifulSoup
from concurrent.futures import ThreadPoolExecutor, as_completed

def find_all_links(base_url, max_pages=50):
    visited, to_visit = set(), {base_url}
    while to_visit and len(visited) < max_pages:
        url = to_visit.pop()
 …
39 0 Open
Automation & scripting medium

How to Build a Mock Route53 DNS API in Python

Create a mock DNS API server in Python that simulates Route53 record lookups and updates using the standard library.

mock-server dns http-server
Python
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse, parse_qs


class DNSUpdateHandler(BaseHTTPRequestHandler):
    records = {"example.com": "1.2.3.4"}

    def do_GET(self):
        domain = parse_qs(urlparse(self.path).query).get("domain", [""])[0]
        if dom…
13 0 Open
Automation & scripting medium

How to Create a Mock Docker Registry Auth Token Server in Python

Build a mock Docker Registry token authentication server that issues signed JWT-like tokens for push and pull access using Python's standard library.

docker registry jwt
Python
import base64
import hashlib
import hmac
import json
import time
from http.server import BaseHTTPRequestHandler, HTTPServer


class TokenAuthHandler(BaseHTTPRequestHandler):
    """Mock Docker Registry token authentication server."""

    SECRET_KEY = b"mock-secret-key"

    def generate_token(self, username: str, pas…
16 0 Open

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.