Home / Use cases / Convert a Web Page to Markdown for RAG

Updated

Convert a Web Page to Markdown for RAG (Main Content Only)

Raw HTML is mostly navigation, scripts and boilerplate. Embedding it wastes tokens and pollutes retrieval; you want the article itself, as Markdown, in chunks.

Try it now on Apify Document to Markdown & JSON (PDF, DOCX, PPTX, HTML, OCR) · $0.004 per one document converted, first 50 pages included · failed items are free

How to do it, step by step

  1. Put the page URLs in URLs.
  2. Turn on HTML main content only to drop nav, header, footer and aside blocks.
  3. Turn on Chunking and set the chunk size in words.
  4. Embed each chunk with its url and headings as metadata.

The exact input used for the example below:

{
  "urls": [
    "https://en.wikipedia.org/wiki/Retrieval-augmented_generation"
  ],
  "htmlMainContentOnly": true,
  "chunking": true,
  "includePages": false
}

Real result

Run yPSEi0ykF3geIB0ut on 2026-12-05: status SUCCEEDED, 1 item(s), 4.8 s of run time. Output shortened for reading (long text cut with “…”).

The article came back as 4,011 words of Markdown in 22 chunks, links kept as absolute URLs.

[
  {
    "url": "https://en.wikipedia.org/wiki/Retrieval-augmented_generation",
    "status": "ok",
    "format": "html",
    "title": "Retrieval-augmented generation - Wikipedia",
    "wordCount": 4011,
    "markdown": "[Jump to content](https://en.wikipedia.org/wiki/Retrieval-augmented_generation#bodyContent)\n\nFrom Wikipedia, the free encyclopedia\n\nType of information retrieval using LLMs\n\nRetrieval-augmented generation (RAG) is a technique that enables [large language models](https://en.wikipedia.org/wiki/Large_language_model) (LLMs) to retrieve and incorporate new information from external data sources.[[1]](h…",
    "chunks": [
      {
        "index": 0,
        "text": "[Jump to content](https://en.wikipedia.org/wiki/Retrieval-augmented_generation#bodyContent)\n\nFrom Wikipedia, the free encyclopedia\n\nType of information retrieval using LLMs\n\nRetrieval-augmented generation (RAG) is a technique that enables [large language models](https://en.wikipedia.org/wiki/Large_language_model) (LLMs) to retrieve and incorporate new information from external data sources.[[1]](h…",
        "word_count": 298,
        "headings": [],
        "page_start": 1,
        "page_end": 1
      },
      {
        "index": 1,
        "text": "[[edit](https://en.wikipedia.org/w/index.php?title=Retrieval-augmented_generation&action=edit&section=1)]\n\nLLMs can provide incorrect information. For example, when Google first demonstrated its LLM tool \"Bard\" (later re-branded to [Google Gemini](https://en.wikipedia.org/wiki/Google_Gemini)), the LLM provided incorrect information about the [James Webb Space Telescope](https://en.wikipedia.org/wi…",
        "word_count": 210,
        "headings": [
          "RAG and LLM limitations"
        ],
        "page_start": 1,
        "page_end": 1
      },
      "… 20 more"
    ]
  }
]

Try it now with your own input

FAQ

Does it run JavaScript?

No; it converts the HTML the server sends. Pages that build their content in the browser return little text and should be rendered first.

Why keep links?

Links are context for the model and let answers cite sources; strip them later if you prefer.

Can it crawl a whole site?

It converts the URLs you give. To list every page of a site first, use the sitemap extractor and pass its URLs.

Related