Tutorial February 3, 2026 7 min read

How to Automate Website Screenshots: A Developer's Guide

Learn how to automate website screenshots for monitoring, archiving, testing, and more. Step-by-step guide with code examples.

Why Automate Screenshots?

Automated screenshots are essential for:

  • Website Monitoring: Detect visual changes and broken pages
  • Visual Regression Testing: Compare before/after deployments
  • Archiving: Create historical records of web pages
  • Competitor Analysis: Track competitor website changes
  • Documentation: Generate up-to-date screenshots for docs

Basic Screenshot Automation

Here's a simple Python script to capture screenshots on a schedule:

import requests
import schedule
import time
from datetime import datetime

API_KEY = "sk_your_key_here"
URLS = [
    "https://example.com",
    "https://example.com/pricing",
    "https://example.com/docs"
]

def capture_screenshots():
    for url in URLS:
        response = requests.post(
            "https://shotapi.net/v1/screenshot",
            headers={
                "X-API-Key": API_KEY,
                "Content-Type": "application/json"
            },
            json={
                "url": url,
                "width": 1280,
                "height": 720,
                "full_page": True
            }
        )

        timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
        filename = f"screenshot_{timestamp}_{url.split('/')[-1]}.png"

        with open(filename, "wb") as f:
            f.write(response.content)

        print(f"Captured: {filename}")

# Run every hour
schedule.every().hour.do(capture_screenshots)

while True:
    schedule.run_pending()
    time.sleep(60)

Visual Regression Testing

Use ShotAPI's /v1/diff endpoint to compare pages and detect changes:

import requests

def compare_pages(url1, url2):
    response = requests.post(
        "https://shotapi.net/v1/diff",
        headers={
            "X-API-Key": "sk_your_key",
            "Content-Type": "application/json"
        },
        json={"url_a": url1, "url_b": url2}
    )

    diff_percentage = float(response.headers.get("X-Diff-Percentage", 0))

    if diff_percentage > 5:  # More than 5% changed
        print(f"WARNING: {diff_percentage}% difference detected!")
        with open("diff.png", "wb") as f:
            f.write(response.content)

    return diff_percentage

# Compare staging vs production
compare_pages(
    "https://staging.example.com",
    "https://example.com"
)

Batch Processing

For capturing multiple URLs efficiently, use the batch endpoint:

curl -X POST https://shotapi.net/v1/batch \
  -H "X-API-Key: sk_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": [
      "https://example.com",
      "https://example.com/about",
      "https://example.com/contact"
    ],
    "options": {
      "width": 1280,
      "format": "png",
      "full_page": true
    }
  }'

Tips for Production

  • Handle rate limits: Add delays between requests
  • Store screenshots: Use cloud storage (S3, GCS) for archives
  • Set up alerts: Notify when visual changes exceed thresholds
  • Use webhooks: Get notified when usage limits approach

Ready to get started?

Try ShotAPI for free. No credit card required.

Start Free