Take website screenshots from the command line with cURL
Capture screenshots, PDFs and Markdown of any web page from your terminal or a shell script with cURL.
3 min read
You don’t need a programming language to capture a web page. A single curl command returns a screenshot, PDF or Markdown of any URL, which makes shotsmith easy to use from shell scripts, cron jobs and CI pipelines.
1. Get an API key
Create a free account (100 renders a month, no card), then export your access key so it stays out of your shell history:
export SHOTSMITH_ACCESS_KEY="shot_…"
2. Your first screenshot
-G with --data-urlencode builds the query string and encodes each value properly, including URLs that have their own ? and &:
curl -G "https://shotsmith.dev/v1/take" \ --data-urlencode "access_key=$SHOTSMITH_ACCESS_KEY" \ --data-urlencode "url=https://shotsmith.dev/sample" \ --data-urlencode "full_page=true" \ --data-urlencode "block_cookie_banners=true" \ -o example.png
3. Fail loudly on errors
By default, curl saves whatever comes back, including a JSON error, into example.png. Add --fail-with-body (curl 7.76 or later) to get a non-zero exit code on errors, which is what you want in scripts and CI. Errors carry a stable error_code and a message saying what to change, and failed renders aren’t billed.
4. PDF, Markdown and HTML
# Print-ready A4 PDF curl -G "https://shotsmith.dev/v1/take" --fail-with-body \ --data-urlencode "access_key=$SHOTSMITH_ACCESS_KEY" \ --data-urlencode "url=https://shotsmith.dev/sample" \ --data-urlencode "format=pdf" --data-urlencode "pdf_paper_format=a4" \ -o example.pdf # The readable content as Markdown, printed to the terminal curl -sG "https://shotsmith.dev/v1/take" --fail-with-body \ --data-urlencode "access_key=$SHOTSMITH_ACCESS_KEY" \ --data-urlencode "url=https://shotsmith.dev/sample" \ --data-urlencode "format=markdown"
5. A script to archive a list of pages
This reads URLs from urls.txt and saves each as a dated, full-page PDF. Failures are reported and skipped, so one broken page doesn’t stop the run. Schedule it with cron to keep a daily record.
#!/usr/bin/env bash
# Archive a list of pages (one URL per line in urls.txt) as dated full-page PDFs.
set -euo pipefail
mkdir -p archive
today=$(date +%Y-%m-%d)
while read -r url; do
[ -z "$url" ] && continue
name=$(echo "$url" | sed -E 's#https?://##; s#[^A-Za-z0-9.-]+#_#g')
if curl -sS --fail-with-body -G "https://shotsmith.dev/v1/take" \
--data-urlencode "access_key=$SHOTSMITH_ACCESS_KEY" \
--data-urlencode "url=$url" \
--data-urlencode "format=pdf" \
--data-urlencode "pdf_print_background=true" \
--data-urlencode "block_cookie_banners=true" \
-o "archive/${today}_${name}.pdf"; then
echo "saved $url"
else
echo "failed $url: $(cat "archive/${today}_${name}.pdf")" >&2
rm -f "archive/${today}_${name}.pdf"
fi
done < urls.txt
For long lists, a single bulk request of up to 100 URLs is faster, and store=true uploads results straight to your own S3 bucket. See archiving web pages for compliance.
6. See the response details
Add -D - to print the response headers. They show the capture ID, whether it came from cache, the render time, and your remaining quota:
X-Capture-Id: 01m8kvpk6jsmeykdfs0wy6awbn X-Cache: MISS X-Render-Time: 296 X-Quota-Remaining: 14998 X-RateLimit-Remaining: 79