NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

Web scraping

How do I scrape JavaScript-heavy sites efficiently?

Treat the browser as a last resort. Most script-built pages fetch their data from JSON endpoints or embed it in the HTML, and reading that directly is many times cheaper than rendering.

The answer in one line

A page that needs JavaScript to show its content still gets that content from somewhere: an API call, a JSON blob inside the HTML, or a server-rendered first view. Find that source and read it with a plain HTTP client. Render with a headless browser only when the data is truly computed in the page or the requests are protected in ways you cannot reproduce, and when you do, strip the browser down to what the page needs.

Look for the data source first

Embedded state

Frameworks that render on the server ship the initial data with the page so the client can hydrate. Search the raw HTML for script tags such as __NEXT_DATA__, __NUXT__, window.__INITIAL_STATE__ or a large application/json block. One json.loads gives you every product on the page, often with fields the visible layout never shows.

Background API calls

Open DevTools, filter the Network tab by Fetch/XHR, and reload or scroll. The requests that return your data usually have readable URLs and JSON bodies, and many accept page and size parameters. Calling them directly is the essence of hidden API scraping. Copy the headers that matter (often a token, a cookie or a custom header), and check whether the endpoint needs a fresh token per session.

GraphQL

If requests go to a single /graphql endpoint, the query is in the request body. Reusing the site's own query, with your variables, is usually stable for months.

When you do need a browser

Some data really requires rendering: requests signed by obfuscated scripts, canvas-drawn content, or flows where a bot check runs in the page. Make that rendering cheap:

import { chromium as headlessChromium } from "playwright";

const renderer = await headlessChromium.launch({ headless: true });
const ctx = await renderer.newContext({ viewport: { width: 1280, height: 860 } });
await ctx.route("**/*", (route) => {
  const kind = route.request().resourceType();
  return ["image", "media", "font"].includes(kind) ? route.abort() : route.continue();
});

const worker = await ctx.newPage();
for (const target of urlBatch) {
  await worker.goto(target, { waitUntil: "domcontentloaded" });
  await worker.locator("[data-test=price]").first().waitFor();
  results.push(await worker.locator("[data-test=price]").allTextContents());
}
await renderer.close();
  • Block heavy resources. Images, video and fonts are rarely needed for extraction. Leave stylesheets alone if layout affects what loads.
  • Reuse the browser. Launching is the slowest step. Keep one browser and open new contexts or pages per job.
  • Wait for data, not for idle. Wait on the selector or response that carries your data instead of full network quiet.
  • Capture responses. Listen to page.on("response") and read the JSON the page fetched, which is cleaner than parsing the rendered DOM.

The hybrid approach

Often the best design uses the browser only for the hard part. Render one page to pass a check, log in or pick up tokens, then copy its cookies and headers into a fast HTTP client for the hundreds of API calls that follow. When the session expires, render again. This keeps browser time to a small fraction of the job.

Challenges on rendered sites

Script-heavy sites are often protected by Cloudflare, DataDome or reCAPTCHA. A challenge page means your selector never appears. Detect it, then solve it instead of retrying: a Cloudflare Turnstile widget needs a token task, a full Cloudflare check page needs a Cloudflare Challenge task with your proxy, and the returned cookie or token then works in both the browser and the HTTP client. The guide on Scrapy with Playwright shows a crawler that renders only selected requests.

Common mistakes

  • Rendering every page because the first one needed it. Test whether later pages expose an API.
  • Using networkidle on sites with live connections, which waits until the timeout every time.
  • Running dozens of browsers on a small machine. Each one needs real memory; measure and size the pool.
  • Ignoring the raw HTML. Server-rendered frameworks often include everything you need without any script running.

For background on the terms, see JavaScript rendering and dynamic scraping.

Common questions

How do I know if a site has a usable JSON API?

Watch the Network tab filtered to Fetch/XHR while the page loads. JSON responses carrying your data are the API.

Is blocking images safe for scraping?

Usually. Few pages need images to render text, but test once, since some lazy loaders wait on image events.

What is __NEXT_DATA__?

A script tag where Next.js sites embed the initial page data as JSON. Parsing it often gives you everything without rendering.

Should I use Playwright or Puppeteer for rendering?

Both work. Playwright adds multi-browser support and auto-waiting; the choice is covered on our comparison page.

Can solved cookies be used outside the browser?

Yes, if you send them with the same user agent and, for IP-bound cookies, through the same proxy.

Keep reading