Guides · Python · requests
Capture a JavaScript-heavy page after it settles in Python with requests
Render a client-side app too early and the capture shows the loading state, not the page: skeleton placeholders where cards should be, a spinner where the chart goes, grey boxes where lazy images land. The page "loaded" — the load event fired — but the app was still fetching its data. "wait_until": "networkidle" moves the goalpost: the render proceeds only after the page stops making network requests for a quiet period.
Below is a complete, runnable Python program using requests (pip install requests). It reads your API key from the SNAPDOK_KEY environment variable — free keys take about thirty seconds and need no card.
import os
import requests
resp = requests.post(
"https://snapdok.io/v1/render",
headers={"Authorization": "Bearer " + os.environ["SNAPDOK_KEY"]},
json={
"url": "https://your-app.com/report/42",
"format": "png",
"full_page": True,
"wait_until": "networkidle",
"delay": 500,
},
timeout=90,
)
resp.raise_for_status()
with open("settled.png", "wb") as f:
f.write(resp.content)
The four stages, in order of patience: commit (bytes started arriving), domcontentloaded (HTML parsed), load (the default — static assets done), and networkidle (the network went quiet, which for an SPA usually means data fetched and rendered). delay then adds a fixed pause on top — the 500 ms here covers entrance animations and fade-ins that happen after the last fetch.
The cost of patience is time: networkidle on a page with analytics beacons or long-polling can take a while to go quiet, and a page that never goes quiet will run into timeout (a 504, never metered). If your page exposes a reliable "ready" element, wait_for_selector is the sharper tool — it waits for exactly the thing you care about, no more. There is a guide for it below.
Same endpoint, one more trick: if the page you are rendering has a form on it, adding "pdf_forms": true to a PDF render brings it back with real, fillable AcroForm fields — a PDF people can type into, not a picture of one. How that works.
Notes for requests
Three requests-specific details the sample already handles. resp.content is the binary body — resp.text would decode PDF bytes as text and corrupt them. raise_for_status() turns a JSON error response into an exception instead of letting it reach the open(..., "wb") call. And requests has no default timeout — without the explicit timeout= a hung connection blocks forever, which matters for a call that drives a real browser and legitimately takes seconds.
Response headers worth reading
| Header | Meaning |
|---|---|
X-Page-Height | Measured document height for the full-page capture. |
X-Cache | Identical requests within 24h replay for free. |
Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.
Related guides
Same task, other stacks
- Capture a JavaScript-heavy page after it settles in Python with httpx
- Capture a JavaScript-heavy page after it settles in Node.js with built-in fetch
- Capture a JavaScript-heavy page after it settles in Node.js with axios
- Capture a JavaScript-heavy page after it settles in PHP with cURL extension
- Capture a JavaScript-heavy page after it settles in Ruby with Net::HTTP
More with Python + requests
- Convert an HTML form to a fillable PDF
- Get a fillable PDF of just the form — no nav, no footer
- Generate a fillable invoice PDF from a web page
- Turn an online registration form into a fillable PDF
- Wait for a JavaScript-rendered form, then make it fillable
- Verify a fillable PDF render without opening the file
- Convert a URL to PDF
- Take a full-page screenshot
- Capture very tall pages as numbered tiles
- Take a retina-quality (2x) screenshot
- Take a JPEG screenshot at a custom viewport size
- Use the 24-hour render cache to cut costs
- Take a screenshot of a URL
- Wait for a specific element before capturing
- Add page numbers and headers to a PDF