Glossary
Dynamic scraping: data that arrives after the page
Dynamic scraping is collecting data from pages whose content loads through scripts, background requests or user interaction rather than arriving in the first HTML response.
Definition
A static page hands you everything in one response. A dynamic page hands you a starting point, and the rest arrives through XHR or fetch calls, infinite scroll, "load more" buttons, tabs, or filters that update results without a reload. Dynamic scraping covers the techniques for getting at that later content. JavaScript rendering is one of them; calling the underlying requests directly is the other.
Two approaches
Drive a browser
Load the page in a headless browser, perform the actions a person would (scroll, click, choose a filter), wait for the new content, and read the DOM. This works on almost anything, including flows with signed parameters computed in the page, but it is slow and heavy.
Call the data requests yourself
Open the browser's network panel, filter by Fetch/XHR, and trigger the action. You will usually see a JSON request with clear parameters: page number, cursor, category id. Reproduce it with an HTTP client, including the headers and cookies it needs. This is often ten or more times faster and returns clean JSON. The hidden API scraping entry goes into detail.
Handling waits
The classic bug in browser based dynamic scraping is reading the page too early. Fixed sleeps either waste time or fail on a slow load. Better options:
- Wait for a specific selector to appear, or for a count of items to grow after a scroll.
- Wait for the network response that carries the data, and read its JSON directly from the browser.
- For infinite scroll, loop: scroll, wait for new items, stop when the count stops changing.
// Puppeteer: capture the JSON the page requests while scrolling
const batches = [];
page.on("response", async (res) => {
if (res.url().includes("/api/feed?cursor=") && res.ok()) {
batches.push(await res.json());
}
});
const pause = (ms) => new Promise((ok) => setTimeout(ok, ms));
await page.goto("https://example.com/feed");
for (let i = 0; i < 10; i++) {
await page.evaluate(() => window.scrollBy(0, document.body.scrollHeight));
await pause(1200); // give the next batch time to arrive
}
Listening to responses gives you structured data while the browser handles cookies, tokens and signatures for you.
Pitfalls
- Endpoints may require tokens that expire, so refresh them from a fresh page load when calls start returning 401 or 403.
- Cursor based pagination means you cannot jump to page 50; you have to walk the chain.
- Rate limits on data endpoints are often stricter than on HTML pages.
- Undocumented endpoints change without notice. Validate responses and alert on shape changes.
Challenges in dynamic flows
Bot checks often guard the data endpoints rather than the page: the first load works, then the XHR that fetches results returns a challenge or a 403. With AWS WAF, the endpoint wants an aws-waf-token cookie; solve the task and add the returned cookie to your client before replaying the request. With reCAPTCHA v3, the page computes a token for a specific action before calling the endpoint; a task with the right pageAction gives you a token to include in that call. See page action.
Common questions
What makes a page dynamic?
Its content arrives after the first HTML response, through scripts, background requests or user interaction.
Is it better to drive a browser or call the API directly?
Calling the data requests directly is faster and cleaner when possible; a browser is the fallback for complex or signed flows.
How do I scrape infinite scroll?
Either call the paginated request behind it, or scroll in a browser and wait for new items until the count stops growing.
Why does the data request fail outside the browser?
It may need cookies, headers or tokens that the page sets, so copy those or let a browser session make the call.
What if the data endpoint returns a challenge?
Solve the matching task, such as AWS WAF, then send the returned cookie or token with your next call to that endpoint.
Keep reading
- JavaScript renderingJavaScript rendering runs page scripts so browser built content appears; you need it only when the data lives nowhere else.
- Hidden API scrapingReading the JSON endpoints a page quietly calls, so you collect clean data without parsing the rendered HTML.
- How do I scrape pages with infinite scroll?Call the JSON endpoint the page uses to load more items, or scroll in a browser until no new items arrive.
- Headless browserA real browser engine running without a visible window, driven by code for tests, screenshots and pages that need JavaScript.