Companion examples and benchmarks for the Screenshot Scout article How to Take Website Screenshots in Python (Benchmarked).
The project has two parts:
- copy-pasteable examples for Playwright, Selenium, and Screenshot Scout;
- reproducible benchmark runners for performance and reliability screenshots.
Use Python 3.11 or newer. Dependencies are pinned for reproducible examples and benchmark runs.
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
playwright install chromiumOn macOS/Linux, activate the environment with source .venv/bin/activate.
Playwright uses the Chromium browser installed by playwright install chromium. Selenium benchmark runs use Selenium Manager to force-download Chrome for Testing instead of using the machine's installed Chrome.
Screenshot Scout examples and benchmarks require an access key.
On Windows PowerShell:
$env:SCREENSHOT_SCOUT_ACCESS_KEY = "your_access_key"On macOS/Linux:
export SCREENSHOT_SCOUT_ACCESS_KEY=your_access_keyEach example is standalone and designed to appear verbatim in the article.
python examples/playwright/screenshot.py
python examples/playwright/full_page_screenshot.py
python examples/playwright/element_screenshot.pypython -m benchmark.runThe combined benchmark command creates one timestamped run folder and runs both performance measurements and reliability screenshot capture into it.
Performance measurements use cold starts: launch, capture, close. The runner records wall time, peak local RAM, and local CPU-seconds with psutil.
By default, performance runs benchmark normal viewport screenshots. Optional --performance-kind full_page and --performance-kind selector modes are available for exploratory measurements; selector mode uses selector from manifests/performance.toml.
Screenshot Scout rendering happens on Screenshot Scout infrastructure, so local CPU/RAM numbers represent only client-side request handling. Wall time still measures how long the screenshot request takes from start to finish.
The reliability runner captures each configured page once per tool and saves screenshots under runs/<timestamp>/screenshots/reliability/. It does not grade pass/fail.
Reliability runs also write runs/<timestamp>/results/reliability_raw.csv for manual grading. After filling the result column, run python -m benchmark.reliability.summarize runs/<timestamp>/results/reliability_raw.csv to create reliability_summary.csv.
The benchmark can also run in Docker:
docker build -t python-screenshot-benchmarks .
docker run --rm -it --shm-size=2g -e SCREENSHOT_SCOUT_ACCESS_KEY="$SCREENSHOT_SCOUT_ACCESS_KEY" -v "$PWD/runs:/app/runs" python-screenshot-benchmarks
python -m benchmark.runLocal browser-library ad and cookie-banner cleanup benchmarks use uBlock Origin Lite. The benchmark downloads a pinned official uBOL release into .cache/ on first use and loads it as an unpacked extension. The extension is not committed to this repository.
Each run writes:
runs/<timestamp>/
screenshots/
reliability/
results/
performance_raw.csv
performance_summary.csv
reliability_raw.csv
reliability_summary.csv # after manual grading and summarization