> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# 批量扫描文档站并提取干净 Markdown 喂给 RAG 或编程助手

> 用 POST /v1/web/map（配合 select_paths/exclude_paths）定向发现文档链接，再用 POST /v1/web/read 按每批 1–10 条提取 Markdown，妥善处理 failed 与 truncated 页面。

想把第三方 API 文档站或更新日志喂给 Claude Code、Cursor 或本地 RAG 知识库，又不想手写脆弱的 HTML 爬虫时，先用 `POST /v1/web/map` 按路径正则筛出目标页面，再用 `POST /v1/web/read` 按每批 1–10 条提取干净的 Markdown 正文。

## 准备与费用范围

* **费用**：`POST /v1/web/map` 按返回 URL 数每条 `$0.001`（单次上限 100 条，0 条免费）；`POST /v1/web/read` 按成功读取页面每条 `$0.002`（`failed` 免费）。扫描并读取 20 页文档总计约 `$0.06`。详见 [BeatAPI 价格页](https://beatapi.io/zh/pricing)。
* **仅限公开网页**：两个接口均拒绝 `localhost`、内网 IP 或带账号密码的 URL（返回 `400 bad_request`）。

## 1. 用路径正则只扫需要的文档目录

接好 [BeatAPI MCP](https://beatapi.io/zh/integrations) 后，可直接交给 Agent 执行：

> 用 `web_map` 扫描 `https://spec.openapis.org`（`select_paths: ["/oas/.*"]`，`max_depth: 2`，`limit: 20`）。挑出有效文档链接后，按每批不超过 10 条调用 `web_read`（`format: "markdown"`，`max_chars: 20000`），每页存为本地 `.md` 文件并附来源 URL；单独列出所有 `failed` 或 `truncated: true` 的链接。

用 HTTP 执行第一步：

```bash
curl -sS https://api.beatapi.io/v1/web/map \
  -H "Authorization: Bearer $BEATAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: web-map-oas-2026-11-23" \
  -d '{"url":"https://spec.openapis.org","select_paths":["/oas/.*"],"exclude_paths":["/blog/.*"],"max_depth":2,"limit":20}' \
  -o mapped-urls.json
```

如果 `urls` 为空，查看返回的 `note`：该起始页可能纯靠前端 JS 生成链接，或只链接了外站。

## 2. 按每批 1–10 条批量提取 Markdown

把筛好的 URL 按每批 **1–10 条**切分后送给 `POST https://api.beatapi.io/v1/web/read`。如果只关心某个具体主题，加上 `query`（最多 400 字符）只取相关段落；要保留全文则省略 `query`：

```bash
curl -sS https://api.beatapi.io/v1/web/read \
  -H "Authorization: Bearer $BEATAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"urls":["https://spec.openapis.org/oas/v3.1.0","https://spec.openapis.org/oas/v3.0.3"],"format":"markdown","max_chars":20000}' \
  -o read-batch-1.json
```

## 3. 妥善处理 `failed[]` 与 `truncated: true`

* **`failed[]` 不影响整批成功**：能读的页面仍会正常出现在 `results[]` 中；记下失败链接及 `reason`（`blocked` 或 `unreachable`），失败 URL 不计费。
* **遇到 `truncated: true` 别让 AI 脑补**：长文档在 `20,000` 字符被截断时，单独对该 URL 重跑一次 `POST /v1/web/read`，把 `max_chars` 调高（最高 `100,000`）或加上精准 `query`。

## 4. 保存本地 Markdown 知识包

示例花费小计（扫描 20 页文档，其中 18 页成功、2 页被目标站拦截）：

| 步骤            | 接口                  | 示例用量                                     | 费用            |
| ------------- | ------------------- | ---------------------------------------- | ------------- |
| 定向扫描文档路径      | `POST /v1/web/map`  | 1 次调用，返回 20 条 URL × `$0.001`             | `$0.0200`     |
| 批量提取 Markdown | `POST /v1/web/read` | 2 次调用，18 条成功 × `$0.002`（2 条 `failed` 免费） | `$0.0360`     |
| **合计**        | **3 次调用**           | **18 份 Markdown 文件**                     | **`$0.0560`** |

将 `results[]` 中每页存为独立 `.md` 文件，在头部记下 `source_url`、`title`、`truncated` 和 `request_id`，并另存一份 `manifest.json` 记录 `failed` 列表，让 RAG 或编程助手明确知道哪些页面已入库、哪些缺失。

## 相关文档

* [BeatAPI Web Search API](https://beatapi.io/zh/web-search-api)
* [Web Search API 参考](/zh/web-search)
* [站点地图范围问答](/zh/faq/web-map-coverage)
* [正文不完整问答](/zh/faq/web-partial-read)
* [文本截断问答](/zh/faq/web-truncated-text)