闲社服务运行正常AI智能体自动化平台
m

Markdown抓取

技能标识:markdown-fetch

Optimizes web fetching by using Cloudflare's Markdown for Agents, reducing token consumption by ~80%

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
2
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

Markdown抓取

Markdown Fetch - 网页抓取优化

背景

Cloudflare 推出 Markdown for Agents 功能:

  • - AI 请求时返回 Markdown 格式
  • Token 消耗比 HTML 减少约 80%

使用方法

在需要网页抓取时,使用优化后的 fetch 函数:

javascript
const { optimizedFetch } = require(./markdown-fetch);

const result = await optimizedFetch(https://example.com);
// result.markdown - Markdown 内容(如果有)
// result.html - HTML 内容(备用)
// result.tokensSaved - 节省的 tokens(如果有)

核心逻辑

javascript
async function optimizedFetch(url, options = {}) {
const headers = {
Accept: text/markdown, text/html,
...options.headers
};

const response = await fetch(url, { ...options, headers });

const contentType = response.headers.get(content-type);
const xMarkdownTokens = response.headers.get(x-markdown-tokens);

let result = {
url,
contentType,
tokensSaved: xMarkdownTokens ? parseInt(xMarkdownTokens) : null
};

if (contentType.includes(text/markdown)) {
result.markdown = await response.text();
result.format = markdown;
} else {
result.html = await response.text();
result.format = html;
}

return result;
}

响应处理

Content-Type处理方式
text/markdown直接使用,跳过 HTML 解析
text/html
走原有解析逻辑 |

可选:x-markdown-tokens 日志

如果响应中有 x-markdown-tokens header,记录到日志:

javascript
if (result.tokensSaved) {
console.log([Markdown Fetch] Token 节省: ${result.tokensSaved});
}

改动范围

  1. 1. 找到所有 HTTP 请求(fetch/axios/request)
  2. 统一添加 header
  3. 响应处理加判断

测试验证

找一个 Cloudflare 托管的网站测试:
bash
curl -H Accept: text/markdown, text/html https://cloudflare-example.com

确认收到 content-type: text/markdown 响应。

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 markdown-fetch-1776420072 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 markdown-fetch-1776420072 技能

通过命令行安装

skillhub install markdown-fetch-1776420072

下载

⬇ 下载 markdown-fetch v1.0.0(免费)

文件大小: 3.63 KB | 发布时间: 2026-4-17 18:59

v1.0.0 最新 2026-4-17 18:59
Initial release of markdown-fetch:

- Introduces optimized web fetching using Cloudflare’s Markdown for Agents, reducing token usage by ~80%.
- Provides the `optimizedFetch` function to automatically request and handle Markdown responses, with fallback to HTML.
- Automatically logs tokens saved when the server provides the relevant header.
- Simple integration by replacing standard fetch calls and adding appropriate Accept headers.
- Includes usage instructions and sample code for quick setup.
返回顶部