DEV Community

Robert from ScreenshotRender

Turn Any Web Page into Clean Markdown for Your LLM with One API Call

If you have ever stuffed a raw HTML response into a prompt, you already know the problem. The model spends tokens on scripts, class names, and layout wrappers, then still misses the paragraph that only appears after JavaScript runs. Large language models do better with Markdown: headings, lists, links, and tables, without the markup tax.

This tutorial shows how to turn a live URL into that clean Markdown in one API call, in Node and in Python, then pass the text to a model. The examples use ScreenshotRender's scrape endpoint, which loads the page in a real browser and returns Markdown by default. I'll also mention a few alternatives if you would rather stay local or use a different service.

Why Markdown, not raw HTML

Three things go wrong when you hand a model a page as HTML.

Tokens. A typical docs page can be 150 to 300 KB of HTML and only a few kilobytes of actual article text. You pay for every tag you send, and you leave less room in the context window for the question you actually care about.

Rendering. A plain fetch or requests.get sees the first HTML document the server sends. On a React or Next.js app, that document is often a shell. The content your users see is painted later, in the browser.

Structure. Markdown keeps the outline the model can use: # headings for chunking in a RAG pipeline, lists, and links. That outline is much easier to split and embed than a tree of <div>s.

You can get some of the way there yourself: fetch the HTML, run Mozilla Readability or Trafilatura, then convert the result with Turndown or markdownify. That works well for static, server-rendered articles. It falls over on JavaScript-heavy pages, and you then have to run Playwright or Puppeteer yourself.

One call, one page of Markdown

ScreenshotRender's scrape endpoint is a POST to https://www.screenshotrender.com/api/v1/scrape. You send a URL and, optionally, the formats you want. markdown is the default. Authenticate with a Bearer key (keys start with sr-), or set SCREENSHOTRENDER_API_KEY. New accounts start with 100 free credits and no credit card. A successful scrape costs 1 credit. Failed calls are not charged.

Here is the same request with cURL, so you can see the shape before touching an SDK:

curl -s -X POST "https://www.screenshotrender.com/api/v1/scrape" \
  -H "Authorization: Bearer $SCREENSHOTRENDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://en.wikipedia.org/wiki/Web_scraping",
    "formats": ["markdown"]
  }'
Enter fullscreen mode Exit fullscreen mode

A successful response looks like this (truncated):

{
  "success": true,
  "data": {
    "markdown": "# Web scraping\n\nWeb scraping is the process of using a program to extract data from websites...",
    "metadata": {
      "title": "Web scraping - Wikipedia",
      "description": "...",
      "sourceURL": "https://en.wikipedia.org/wiki/Web_scraping",
      "url": "https://en.wikipedia.org/wiki/Web_scraping",
      "statusCode": 200,
      "contentType": "text/html; charset=UTF-8"
    }
  },
  "creditsUsed": 1
}
Enter fullscreen mode Exit fullscreen mode

Check two layers of status. success tells you the API call itself worked. data.metadata.statusCode is the HTTP status of the page (a 200 with success: true can still wrap a 404 page). The Markdown you want is data.markdown.

Node.js

Install the official SDK (Node 18 or later):

npm install screenshotrender
Enter fullscreen mode Exit fullscreen mode
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({
  apiKey: process.env.SCREENSHOTRENDER_API_KEY,
});

const doc = await screenshotrender.scrape(
  "https://en.wikipedia.org/wiki/Web_scraping",
  { formats: ["markdown"] },
);

if (doc.metadata.statusCode !== 200) {
  throw new Error(`Page returned ${doc.metadata.statusCode}`);
}

console.log(doc.metadata.title);
console.log(doc.markdown.slice(0, 500));
Enter fullscreen mode Exit fullscreen mode

The SDK returns the response's data object, so you read doc.markdown directly instead of response.data.markdown.

Python

The Python SDK needs 3.9 or later:

pip install screenshotrender
Enter fullscreen mode Exit fullscreen mode
import os
from screenshotrender import ScreenshotRender

screenshotrender = ScreenshotRender(
    api_key=os.environ["SCREENSHOTRENDER_API_KEY"]
)

doc = screenshotrender.scrape(
    "https://en.wikipedia.org/wiki/Web_scraping",
    formats=["markdown"],
)

if doc.metadata.status_code != 200:
    raise RuntimeError(f"Page returned {doc.metadata.status_code}")

print(doc.metadata.title)
print(doc.markdown[:500])
Enter fullscreen mode Exit fullscreen mode

In Python, fields also accept snake_case: doc.metadata.status_code is the same value as doc["metadata"]["statusCode"].

Options that matter once you leave the happy path

The defaults are already aimed at LLM input. onlyMainContent is true, so headers, navs, and footers are dropped. Ads and cookie banners are blocked. Images embedded as base64 are removed. Cached copies up to two days old are accepted, which is fine for docs that rarely change. Set maxAge to 0 when you need a live load.

A few options come up constantly in agent and RAG work:

Wait for late content. waitFor is extra milliseconds after the page loads. Use it when the main article appears a moment after hydration.

Click, then read. actions runs up to 50 steps in a real browser before the page is captured. A common pattern is clicking "Load more" and waiting:

const doc = await screenshotrender.scrape("https://example.com/changelog", {
  formats: ["markdown"],
  waitFor: 2000,
  actions: [
    { type: "click", selector: "button.load-more" },
    { type: "wait", milliseconds: 1000 },
  ],
});
Enter fullscreen mode Exit fullscreen mode

Other documented actions include write, press, scroll, executeJavascript, and waiting on a CSS selector: { type: "wait", selector: "#results" }.

Pages that block ordinary requests. Set proxy: "enhanced" to load the page through enhanced proxies. That costs 5 credits a page instead of 1. ScreenshotRender always respects robots.txt. Requests that ask to ignore robots are refused.

Treat the page as untrusted. A page can hide instructions aimed at your model. For any workflow that then calls an AI format, set checkPromptInjection: true (4 extra credits) to scan the page first. Even with that flag, keep the Markdown in a clearly delimited user-data block in your prompt, and do not let a fetched page execute tools on its own.

You can also ask for more than Markdown in the same call, for example formats: ["markdown", "links"], without a second request. Other formats on the same endpoint include cleaned html, summary, and a json format when you want structured fields instead of prose. Those last AI formats cost extra credits.

Feed the Markdown to a model

Once you have doc.markdown, the model call is ordinary. Keep a hard cap so a long article cannot blow the context window, and label the page as untrusted content:

const markdown = doc.markdown.slice(0, 24_000);

const prompt = `Answer the question using only the article below.
If the article does not contain the answer, say you cannot tell.

Question: ${question}

<article url="${doc.metadata.url}" title="${doc.metadata.title}">
${markdown}
</article>`;
Enter fullscreen mode Exit fullscreen mode

Pass prompt to whatever model you already use. For a RAG pipeline, split on headings first, embed the chunks, and retrieve before you prompt. Because the text is already Markdown, heading-aware chunkers have a clean outline to work with.

PDFs and other documents

Scrape is for web pages. If the URL points at a PDF, or you have a file on disk (PDF, DOCX, XLSX, PPTX, EPUB, and a few other office formats), use the parse endpoint instead. Credits are 1 per page it reads.

# A public PDF URL
doc = screenshotrender.parse(
    "https://arxiv.org/pdf/1706.03762",
    parsers=[{"type": "pdf", "max_pages": 3}],
)
print(doc.markdown)
Enter fullscreen mode Exit fullscreen mode

Other ways to get there

You do not need a hosted API for every page.

  • Jina Reader (r.jina.ai) is a quick way to turn a public URL into Markdown, and it is enough for many static articles.
  • Firecrawl offers a similar scrape-to-Markdown API if you already have an account there.
  • Trafilatura (Python) and Mozilla Readability are strong local extractors when you can fetch the HTML yourself.
  • Playwright (or Puppeteer) plus Turndown is the self-hosted path for JavaScript-heavy sites, at the cost of running and scaling a browser.

A hosted renderer is worth it when you do not want to operate that browser fleet, or when a plain fetch keeps coming back with an empty shell or a block page.

If you just want to try a single URL without writing code, ScreenshotRender also has a free HTML to Markdown converter that accepts pasted HTML or a public page.

Wrap-up

The working pattern is small: load the page in a browser, convert the main content to Markdown, check the page status, then send a capped, clearly delimited excerpt to your model. In Node or Python, that first step is one scrape call. From there, the same Markdown can go into a chat prompt, a RAG index, or a daily research job, without dragging a full HTML document along with it.

Top comments (0)