# Web Search to Markdown for RAG & LLMs (`datamule/rag-web-search-to-markdown`) Actor

Search the web and get LLM-ready Markdown: one row per result with title, URL, snippet and cleaned page text. DuckDuckGo + Bing, no API keys, robots.txt respected. $0.0018 per result, no start fee for the search itself.

- **URL**: https://apify.com/datamule/rag-web-search-to-markdown.md
- **Developed by:** [Datamule](https://apify.com/datamule) (community)
- **Categories:** AI, Developer tools, SEO tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.26 / 1,000 search result with page markdowns

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## Web Search to Markdown for RAG and LLMs

**Search the web, get clean Markdown.** Give it search queries; get one row per result with the **title, URL, snippet and the page's main text as Markdown**, ready for an LLM or RAG pipeline. No API keys, no browser, no proxies to configure.

**Price: $0.0018 per result** (pay-per-event, no start fee for the search itself; volume tiers up to 50% off). Each result row includes its Markdown, so one result = one search hit plus its page content. Apify platform usage is separate and small (256 MB Actor).

### Example

Input:

```json
{"queries": ["python web scraping tutorial"], "maxResults": 3, "fetchPages": true}
```

Output row (shortened):

```json
{"query": "python web scraping tutorial", "rank": 1, "title": "Python Web Scraping Tutorial - GeeksforGeeks",
 "url": "https://www.geeksforgeeks.org/python/python-web-scraping-tutorial/",
 "snippet": "Web scraping is the process of extracting data from websites automatically…",
 "searchEngine": "duckduckgo", "fetchStatus": "ok", "markdown": "# Python Web Scraping Tutorial\n\n…", "markdownChars": 8123}
```

### Input

| Field | Meaning |
|---|---|
| `queries` (required) | Search queries, up to 50 per run. |
| `maxResults` | Results per query, 1-10 (default 5). |
| `fetchPages` | `true` (default): download each result page and return cleaned Markdown. `false`: title, URL and snippet only (faster). Same price. |
| `maxCharsPerPage` | Truncate Markdown per page (default 10,000) to fit your context budget. |
| `searchEngine` | `auto` (default: DuckDuckGo, tops up from Bing), `duckduckgo` or `bing`. |

### Output fields

`query`, `rank`, `title`, `url`, `snippet`, `searchEngine`, `pageTitle`, `markdown`, `fetchStatus`, `markdownChars`, `scrapedAt`.
`fetchStatus` says why a page has no Markdown: `ok`, `blocked_by_robots_txt`, `http_403`, `unsupported_content_type` (PDFs etc.), `empty_page`, `fetch_failed`, `skipped_non_public_url`. Such rows are still returned and billed as a search result (title, URL and snippet are real data).

### Behaviour and limits

- **Sources:** public DuckDuckGo HTML and Bing HTML result pages. Search engines can throttle automated traffic; the Actor retries 429/5xx and falls back between engines. A query that returns nothing from any engine is skipped with a warning; the run fails only if no query returns any result.
- **Polite fetching:** identifying User-Agent, `robots.txt` honoured, public http(s) hosts only, bodies capped at 2 MB. No logins, no paywall bypass, no personal-data extraction.
- Markdown comes from a lightweight HTML cleaner (headings, lists, links, code, emphasis; navigation, scripts and footers removed). JavaScript-rendered pages may return little text.
- Duplicate URLs within a query are removed. These are not Google results; ranking may differ from your browser.
- **Budget safe:** the Actor stops cleanly at your "maximum charge per run" and delivers every row it could afford.
- Use of search-engine results is subject to those engines' terms; you are responsible for how you use the output.

# Actor input Schema

## `queries` (type: `array`):

One search query per line, e.g. 'best python web scraping libraries'. Each query returns up to 'Results per query' rows. Up to 50 queries per run.

## `maxResults` (type: `integer`):

How many search results to return for each query (1-10). You pay per returned result.

## `fetchPages` (type: `boolean`):

If on, each result page is downloaded (robots.txt respected) and its main text is returned as clean Markdown in the 'markdown' field. If off, you only get title, URL and snippet (faster). Same price either way.

## `maxCharsPerPage` (type: `integer`):

Truncate each page's Markdown to this many characters to fit your LLM context budget (500-100000).

## `searchEngine` (type: `string`):

Auto tries DuckDuckGo first and tops up from Bing if needed. Pick one engine to pin the source.

## Actor input object example

```json
{
  "queries": [
    "python web scraping tutorial"
  ],
  "maxResults": 3,
  "fetchPages": true,
  "maxCharsPerPage": 10000,
  "searchEngine": "auto"
}
```

# Actor output Schema

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

No description

# 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 = {
    "queries": [
        "python web scraping tutorial"
    ],
    "maxResults": 3
};

// Run the Actor and wait for it to finish
const run = await client.actor("datamule/rag-web-search-to-markdown").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 = {
    "queries": ["python web scraping tutorial"],
    "maxResults": 3,
}

# Run the Actor and wait for it to finish
run = client.actor("datamule/rag-web-search-to-markdown").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 '{
  "queries": [
    "python web scraping tutorial"
  ],
  "maxResults": 3
}' |
apify call datamule/rag-web-search-to-markdown --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,datamule/rag-web-search-to-markdown"
        }
    }
}
```

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/LUCWrM5oFsmymLEBj/builds/1vU454VUUCqPLRIC6/openapi.json
