Ready-to-copy Python code for capturing website screenshots, generating PDFs, and processing pages at scale. Uses requests.
The simplest way to capture a screenshot. Just a URL and your API key.
import requests
resp = requests.get("https://api.screenshotdev.com/v1/screenshot", params={
"url": "https://example.com",
"access_key": "YOUR_ACCESS_KEY"
})
with open("screenshot.png", "wb") as f:
f.write(resp.content)Complete working script with options for viewport, format, full page capture, and error handling.
import requests
import sys
from pathlib import Path
API_KEY = "YOUR_ACCESS_KEY"
BASE = "https://api.screenshotdev.com/v1/screenshot"
def take_screenshot(
url: str,
format: str = "webp",
width: int = 1280,
full_page: bool = False,
dark_mode: bool = False,
) -> bytes:
resp = requests.get(BASE, params={
"url": url,
"access_key": API_KEY,
"format": format,
"width": width,
"full_page": full_page,
"dark_mode": dark_mode,
})
resp.raise_for_status()
return resp.content
if __name__ == "__main__":
url = sys.argv[1] if len(sys.argv) > 1 else "https://example.com"
img = take_screenshot(url, format="webp", width=1440, full_page=True)
Path("screenshot.webp").write_bytes(img)
print(f"Saved screenshot.webp ({len(img)} bytes)")PDF generation, batch processing, webhooks, CSS/JS injection, and S3 upload.
import requests
resp = requests.get("https://api.screenshotdev.com/v1/pdf", params={
"url": "https://example.com",
"access_key": "YOUR_ACCESS_KEY",
"format": "a4",
"landscape": False,
"margin": "20px",
})
resp.raise_for_status()
with open("page.pdf", "wb") as f:
f.write(resp.content)import requests
from concurrent.futures import ThreadPoolExecutor
API_KEY = "YOUR_ACCESS_KEY"
urls = [
"https://example.com",
"https://github.com",
"https://news.ycombinator.com",
]
def capture(url: str) -> tuple[str, int]:
resp = requests.get("https://api.screenshotdev.com/v1/screenshot", params={
"url": url,
"access_key": API_KEY,
"format": "webp",
})
resp.raise_for_status()
filename = url.split("//")[1].replace("/", "_") + ".webp"
with open(filename, "wb") as f:
f.write(resp.content)
return filename, len(resp.content)
with ThreadPoolExecutor(max_workers=5) as pool:
for name, size in pool.map(capture, urls):
print(f" {name} ({size:,} bytes)")import requests
resp = requests.post("https://api.screenshotdev.com/v1/screenshot", json={
"url": "https://example.com",
"access_key": "YOUR_ACCESS_KEY",
"webhook_url": "https://your-app.com/api/webhooks/screenshot",
"format": "webp",
"full_page": True,
})
resp.raise_for_status()
job = resp.json()
print(f"Job queued: {job['id']}")
# Your webhook endpoint will receive the result when readyimport requests
resp = requests.get("https://api.screenshotdev.com/v1/screenshot", params={
"url": "https://example.com",
"access_key": "YOUR_ACCESS_KEY",
"inject_css": "body { font-family: 'Inter', sans-serif; } .ad, .banner { display: none; }",
"inject_js": "document.querySelectorAll('[data-cookie-banner]').forEach(el => el.remove())",
"block_ads": True,
})
resp.raise_for_status()
with open("clean.webp", "wb") as f:
f.write(resp.content)import requests
import boto3
# 1. Capture the screenshot
resp = requests.get("https://api.screenshotdev.com/v1/screenshot", params={
"url": "https://example.com",
"access_key": "YOUR_ACCESS_KEY",
"format": "webp",
})
resp.raise_for_status()
# 2. Upload to S3
s3 = boto3.client("s3")
s3.put_object(
Bucket="my-screenshots",
Key="captures/example-com.webp",
Body=resp.content,
ContentType="image/webp",
)
print("Uploaded to s3://my-screenshots/captures/example-com.webp")Test the API in the interactive playground — pre-filled with Python snippets.
Install the HTTP library used in the examples above.
pip install requestsUses requests. Any HTTP client that supports GET requests will work.
100 free API calls per month. No credit card. First screenshot in under 30 seconds.