ScreenAPI

Guides

Screenshot a single element of a page with a CSS selector

Capture only a chart, a pricing table, a tweet or a product card instead of the whole page, using a CSS selector. Examples with curl, Node.js and Python.

Often you do not want the whole page: just the chart for a weekly report, the pricing table of a competitor, or a product card for a newsletter. Pass a CSS selector and ScreenAPI crops the capture to that element.

The element parameter

curl "https://getscreenapi.com/api/v1/screenshot?url=https://example.com&element=main%20h1" \
  -H "x-api-key: YOUR_KEY" -o title.png

The first element matching the selector is captured, with its exact size. If nothing matches, the API answers 422 SELECTOR_NOT_FOUND and the capture is not counted.

Finding a good selector

  1. Open the page in Chrome, right-click the element, choose Inspect.
  2. In the Elements panel, right-click the highlighted line and choose Copy > Copy selector.
  3. Prefer short, stable selectors (#pricing, [data-testid="chart"]) over long generated ones like div:nth-child(3) > div > div, which break when the page changes.

Content that appears late

Charts and widgets are often drawn by JavaScript after the page loads. Add wait_for_selector for the same element, and a short delay for animations:

const res = await fetch("https://getscreenapi.com/api/v1/screenshot", {
  method: "POST",
  headers: { "x-api-key": process.env.SCREENAPI_KEY, "content-type": "application/json" },
  body: JSON.stringify({
    url: "https://example.com/dashboard",
    element: "#revenue-chart",
    wait_for_selector: "#revenue-chart canvas",
    delay: 800,
    retina: true, // sharper image for reports
  }),
});

Element hidden behind a tab or a button?

Use click to press it first (for example click: "#tab-yearly"), or styles to inject CSS that reveals it.

Element captures cost the same as any other: one credit.

Get a free key