DEV Community

neuralbyte
neuralbyte

Posted on

Web Scraping API or Playwright? Test the Evidence You Need

“Does it render JavaScript?” usually isn't enough to decide between a scraping API and Playwright. The decision turns on what evidence your application needs. Can a bounded request return the exact offer, or do you need to observe the browser and branch after an action?

Use a single accepted URL to test retrieval and a controlled fixture to test stateful interaction. A tool can fit the first job and be irrelevant to the second.

Compare the actual work

Requirement Request-based collection Playwright
Read a known URL and preserve the source Request Markdown, HTML, or a supported artifact and validate the task result. Navigate to the page, extract the section and save the evidence you choose.
Read dynamically loaded markup Use a documented wait or selector within the request. Observe the page directly and wait on an explicit condition.
Choose a variant and branch on how the page responds Check whether the request's supported actions can represent the flow. Run an interaction, assert the resulting state, and branch if necessary.
Run a catalog repeatedly Budget for per-source tasks, result references, and accepted records. Budget for browser workers, context lifecycle, locator maintenance and diagnostic time.

A model name is an input to a catalog or search integration. Once you have an approved candidate URL, assess these collection paths separately from discovery.

Test a known page with Crawl MCP

Nstdata Crawl is a Web Crawling API for LLM-ready data. For an assistant workflow, attach its official MCP server over local stdio or hosted Streamable HTTP at https://mcp.nstdata.io/crawl. Use protected client settings for the API key or complete the hosted OAuth flow.

Make a single smoke request from the MCP client to check the integration. This sample requests a fixed test page.

{
  "name": "nstdata_crawl_scrape",
  "arguments": {
    "url": "https://example.com/",
    "mode": "sync",
    "formats": ["markdown"],
    "options": {"timeout": 25000}
  }
}
Enter fullscreen mode Exit fullscreen mode

Check status and success before reading content. If the task returns a Markdown reference, call nstdata_crawl_read_result with the reference, format: "markdown" and first offset 0. Advance using nextOffset within your read budget. For an accepted product page with a dynamic offer, set options.jsRender.waitForSelector to a verified offer marker and record the specific evidence.

Applications can also call the Crawl Python SDK. In either route, keep the service's completion state and your own field acceptance separate.

Test an interaction with Playwright

Run the following JavaScript example with Node.js 22. Install playwright-core@1.65.1 and its expected Chromium using:

npm install playwright-core@1.65.1
npx playwright-core install chromium
Enter fullscreen mode Exit fullscreen mode

Save the code as offer.mjs and run node offer.mjs. It creates an in-memory demonstration page. The synthetic offer only appears after selecting Black. The code checks the initial selector state, waits for the exact resulting offer, and verifies that the control is selected.

import assert from "node:assert/strict";
import { chromium } from "playwright-core";

const browser = await chromium.launch();
try {
  const context = await browser.newContext();
  const page = await context.newPage();
  await page.setContent(`
    <main>
      <h1>Demo Headphones</h1>
      <button type="button" aria-pressed="false">Black</button>
      <output data-testid="offer">Select a variant</output>
    </main>
    <script>
      document.querySelector("button").addEventListener("click", (event) => {
        event.currentTarget.setAttribute("aria-pressed", "true");
        setTimeout(() => {
          document.querySelector("output").textContent = "Black | USD 249.00 | In stock";
        }, 100);
      });
    </script>
  `);
  const variant = page.getByRole("button", { name: "Black" });
  assert.equal(await variant.getAttribute("aria-pressed"), "false");
  await variant.click();
  await page.getByText("Black | USD 249.00 | In stock", { exact: true })
    .waitFor({ state: "visible", timeout: 3000 });
  assert.equal(await variant.getAttribute("aria-pressed"), "true");
  console.log(await page.getByTestId("offer").innerText());
} finally {
  await browser.close();
}
Enter fullscreen mode Exit fullscreen mode

The local fixture prints Black | USD 249.00 | In stock. That is a deterministic test output. For a real retailer, start with a permitted page, confirm the identity of the product, and scope your locators to its offer controls. Wait for an updated state tied to the chosen variant before writing a price.

Use a fresh isolated browser context when an experiment needs repeatability. In a managed Chromium session, use the documented Cloud Browser session and CDP lifecycle to attach, verify the active page, and stop the session after the work.

Design a clean handoff between the two paths

A practical workflow starts with the API for approved URL-based retrieval. If a supported render option can expose the needed content, validate the returned fields and keep the evidence. When the accepted outcome genuinely requires stateful interaction, route that job to a browser worker. Keep security and access failures distinct from missing evidence and stop at an access restriction.

The original Nstdata Local MCP pilot accepted six observations for three US and UK listings. It demonstrated retrieval and field acceptance under the recorded settings. The Playwright fixture above exercises a different requirement. A live cost or accuracy comparison would need the same authorized target, variant, time window and acceptance checks on both paths.

Choose the collection path by the kind of evidence it can reliably produce. Put a common validator after both integrations so a downstream job sees the source, observation time and acceptance outcome regardless of how the page was obtained.

Top comments (0)