# LLM-Ready Web Extractor — HTML & PDF to Markdown (`lilambd/llm-ready-web-extractor`) Actor

Extract public static HTML and text-layer PDFs into Markdown, structured JSON or character-bounded chunks. One row per successful document with source URL and metadata. Includes a ready-to-run PDF example. USD 0.0018 per result row. No source API key; no OCR or JavaScript rendering.

- **URL**: https://apify.com/lilambd/llm-ready-web-extractor.md
- **Developed by:** [Lilambd Crossing](https://apify.com/lilambd) (community)
- **Categories:** AI, Developer tools
- **Features:** Limited permissions, Single-tenant, Server interface
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.80 / 1,000 extracted documents

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## LLM-Ready Web Extractor

Turn public static HTML/XHTML and text-layer PDFs into Markdown, structured JSON or text chunks for retrieval. Each successfully extracted document produces one dataset row with its source URL and metadata.

### Try it in Apify Console

1. Open [LLM-Ready Web Extractor](https://apify.com/lilambd/llm-ready-web-extractor) and open its input editor. The Actor uses paid per-result pricing.
2. Use the input below. It is the same one-page W3C PDF used by the default Console example.
3. Start the run, then open its **Dataset** to view or export the result. Check that rows were produced; a successful run can still contain zero results.

```json
{
  "urls": ["https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"],
  "maxPages": 1,
  "format": "markdown"
}
```

#### Actual output example

This result comes from the same public PDF in a verified run. Only the variable `durationMs` field is omitted here.

```json
{
  "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
  "canonicalUrl": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
  "title": "dummy.pdf",
  "language": null,
  "headings": [],
  "tables": [],
  "metadata": { "contentType": "application/pdf", "pageCount": 1 },
  "markdown": "Dummy PDF file"
}
```

### Pricing

**USD 0.0018 per successfully extracted document row** written to the default dataset, equivalent to USD 1.80 per 1,000 rows. One document is one row in all three output formats; a `chunks` array stays inside that row. Failed URLs do not create result rows. Platform usage or account charges may apply separately; review Apify's run estimate and pricing for your account.

### Input

Supply **exactly one** of `urls` or `query`. The Console's prefilled PDF is an example, not an implicit URL used when the runtime input is empty. API callers must send the example JSON explicitly; a POST without URLs or a query is invalid.

| Field | Default | Behavior |
| --- | --- | --- |
| `urls` | None | 1–20 public HTTP(S) URLs. Only the supplied URLs are attempted; there is no recursive link crawling. |
| `query` | None | Search document titles in the public RFC Editor index. Every query word must occur in the title. This is not general web search. Up to 200 characters. |
| `maxPages` | 5 | Maximum distinct URLs to attempt, including failures. Range 1–20; the prefilled PDF example uses 1. |
| `format` | `markdown` | `markdown`, `json` or `chunks`, as described below. |
| `chunkLength` | 1200 | Maximum characters per chunk, not tokens. Range 200–5000. Used only by `chunks`. |

For chunks, change only the output settings in the same PDF example:

```json
{
  "urls": ["https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"],
  "maxPages": 1,
  "format": "chunks",
  "chunkLength": 500
}
```

### Output and failures

All formats retain `url`, `canonicalUrl`, `title`, `language`, `metadata` and `durationMs` where available.

- `markdown`: top-level `markdown`, `headings` and `tables`.
- `json`: `document` contains `markdown`, `headings` and `tables`.
- `chunks`: top-level `chunks` is an array of Markdown text segments; `headings` and `tables` remain top-level.

HTML tables expand row and column spans. PDF metadata includes the page count; PDF headings are inferred from text. Language and other metadata can be absent or null.

In normal batch runs, failed URLs and their error codes are saved under `FAILURES` in the run's default key-value store. A run with no extracted rows has no useful dataset output, even if its status is `SUCCEEDED`.

### Scope and limits

The HTTP crawler checks robots.txt before requests and redirects and skips recognizable login gates. It does not render JavaScript or use a browser. Use public documents you have permission to process. Private/internal addresses, URLs with credentials and unsupported ports are rejected.

Text-layer PDFs of up to 50 pages are supported; larger PDFs are rejected. OCR, scanned-image text, PDF table reconstruction, authenticated pages and access-control bypass are outside the current scope. Results depend on the source markup and accessible text. Extraction does not generate embeddings or guarantee an answer from an LLM.

### Local development

Requires Node.js 24 and npm. From this directory:

```sh
npm ci
npx --no-install apify validate-schema .actor/input_schema.json
npx --no-install apify run --no-purge --input-file samples/input.json
npm run check
npm test
```

Local rows go to the default dataset. Use a fresh `APIFY_LOCAL_STORAGE_DIR` for independent runs.

### Standby and MCP

The implementation includes an MCP Streamable HTTP endpoint at `/mcp` and the `extract_web_pages` tool. For local development, set `LOCAL_STANDBY_PORT=19146` and run `npm start`; the server binds to loopback. `GET /health` reports readiness. Tool calls return `{rows, failures}` directly rather than writing batch dataset rows. Cloud MCP charging and persistence have not been verified here; the pricing and Dataset instructions above describe normal batch runs. Use the batch workflow for the documented example.

# Actor input Schema

## `query` (type: `string`):

Alternative to URLs: match every query word in RFC Editor document titles. Clear the prefilled URLs before using query. Not general web search.

## `urls` (type: `array`):

1–20 public HTTP(S) URLs you have permission to process. Supply URLs or query, never both. Static HTML and text-layer PDF only; no recursive crawling.

## `maxPages` (type: `integer`):

Maximum distinct URLs to attempt, including failures (1–20). The PDF example uses 1.

## `format` (type: `string`):

One row per document: markdown has top-level text/headings/tables; json nests these in document; chunks puts text segments in one chunks array.

## `chunkLength` (type: `integer`):

Maximum characters per text chunk, not tokens. Used only by chunks format.

## Actor input object example

```json
{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "maxPages": 1,
  "format": "markdown",
  "chunkLength": 1200
}
```

# Actor output Schema

## `results` (type: `string`):

Rows in the default dataset

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "urls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    ],
    "maxPages": 1
};

// Run the Actor and wait for it to finish
const run = await client.actor("lilambd/llm-ready-web-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "urls": ["https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"],
    "maxPages": 1,
}

# Run the Actor and wait for it to finish
run = client.actor("lilambd/llm-ready-web-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "maxPages": 1
}' |
apify call lilambd/llm-ready-web-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,lilambd/llm-ready-web-extractor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/V29nlIr4pBYZ21LpB/builds/yiM4lcGkNez5uX2ED/openapi.json
