markdown-fetch
Optimizes web fetching by using Cloudflare's Markdown for Agents, reducing token consumption by ~80%
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/howtimeschange/markdown-fetchMarkdown Fetch - 网页抓取优化
背景
Cloudflare 推出 Markdown for Agents 功能:
- AI 请求时返回 Markdown 格式
- Token 消耗比 HTML 减少约 80%
使用方法
在需要网页抓取时,使用优化后的 fetch 函数:
const { optimizedFetch } = require('./markdown-fetch');
const result = await optimizedFetch('https://example.com');
// result.markdown - Markdown 内容(如果有)
// result.html - HTML 内容(备用)
// result.tokensSaved - 节省的 tokens(如果有)
核心逻辑
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,记录到日志:
if (result.tokensSaved) {
console.log(`[Markdown Fetch] Token 节省: ${result.tokensSaved}`);
}
改动范围
- 找到所有 HTTP 请求(fetch/axios/request)
- 统一添加 header
- 响应处理加判断
测试验证
找一个 Cloudflare 托管的网站测试:
curl -H "Accept: text/markdown, text/html" https://cloudflare-example.com
确认收到 content-type: text/markdown 响应。
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-howtimeschange-markdown-fetch": {
"enabled": true,
"auto_update": true
}
}
}Related Skills
clawbot-network
Connect multiple OpenClaw instances across devices (VPS, MacBook, Mac Mini) for distributed agent collaboration. Enables clawdbot-to-clawdbot communication, cross-device @mentions, task assignment, and group chat. Use when you have OpenClaw running on multiple machines that need to communicate and collaborate.
minimax-opus-tune
将 MiniMax 调教成"免费 Claude"的方法论。通过配置 SOUL.md 文件,实现智能分块输出、思考链隐藏、Claude 风格回复等高级特性。适用于希望提升 MiniMax 输出质量、减少截断、增加 Claude 风格体验的用户。
agent-network
Multi-Agent group chat collaboration system inspired by DingTalk/Lark. Enables AI agents to chat in groups, @mention each other, assign tasks, make decisions via voting, and collaborate. Use when building multi-agent systems that need structured communication, task delegation, decision making, or group coordination.