从任意 URL 提取干净的 Markdown:PageBolt /extract 接口
Source: Dev.to
原始 HTML 的问题
当 AI 代理读取网页时,将原始 HTML 输入大型语言模型(LLM)会迫使它在脚本、广告、导航菜单、页脚以及其他模板内容中进行筛选。
典型拆分:
- 脚本和样式表 – 被模型忽略
- 导航菜单 – 被忽略
- 广告和跟踪像素 – 被忽略
- ≈10 KB 的模板内容 – 浪费的 token
- ≈2 KB 的实际内容 – 你需要的部分
如果代理处理 50 KB 的 HTML 只提取出 2 KB 的有用文本,大约 96 % 的 token 被浪费,导致成本和延迟增加。
介绍 PageBolt 的 /extract 端点
PageBolt 提供一个单一功能的 API,能够:
- 接收一个 URL。
- 提取主要文章/内容。
- 将结果返回为干净的 Markdown(以及可选的元数据)。
该响应可直接用于任何大型语言模型(LLM)。
简单的 JavaScript 示例
// fetch clean Markdown from a URL
const response = await fetch('https://api.pagebolt.com/v1/extract', {
method: 'POST',
headers: {
'Authorization': `Bearer YOUR_API_KEY`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: 'https://example.com/blog/article'
})
});
const data = await response.json();
console.log(data.markdown);
// => "# Article Title\n\nArticle content in clean Markdown..."
使用 /extract 与 LLM(Anthropic Claude)
const Anthropic = require('@anthropic-ai/sdk');
const client = new Anthropic();
async function summarizeResearchPaper(paperUrl) {
// 1️⃣ Extract the paper as Markdown
const extractResponse = await fetch('https://api.pagebolt.com/v1/extract', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.PAGEBOLT_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: paperUrl,
format: 'markdown'
})
});
const { markdown, title, author } = await extractResponse.json();
// 2️⃣ Pass clean Markdown to Claude
const message = await client.messages.create({
model: 'claude-opus-4-5',
max_tokens: 1024,
messages: [
{
role: 'user',
content: `Summarize this research paper in 3 bullet points:
Title: ${title}
Author: ${author}
Content:
${markdown}`
}
]
});
return message.content[0].text;
}
// Example usage
const summary = await summarizeResearchPaper('https://arxiv.org/pdf/2406.12345');
console.log(summary);
令牌效率提升
| 场景 | 输入令牌 | 输出令牌 | 约算费用* |
|---|---|---|---|
| 原始 HTML(未提取) | 50,000 | 500 | ~¥1.50 |
干净的 Markdown(使用 /extract) | 2,000 | 500 | ~¥0.06 |
*成本基于典型的 LLM 定价;实际费率可能有所不同。
使用干净的 Markdown 可将令牌使用量降低约 ≈25×,从而降低成本并加快响应速度。它还能提升 LLM 的理解能力,因为 Markdown 更符合文本结构的自然表达方式。
常见用例
- Research aggregator – 提取并汇总数十篇论文。
- Competitive intelligence – 抓取竞争对手的网页进行分析。
- Documentation agent – 导入 API 文档并回答开发者问题。
- News digest – 收集每日文章并生成简报。
- Content curator – 获取博客文章并进行分类。
- Customer support – 抓取帮助中心文章以训练客服机器人。
示例 API 响应
{
"markdown": "# Article Title\n\nArticle content...",
"title": "Article Title",
"author": "Author Name",
"published_date": "2026-03-18",
"word_count": 1200,
"estimated_reading_time_minutes": 5
}
该 JSON 包含 Markdown 正文以及可用于显示或存储的有用元数据。
定价
| 计划 | 每月价格 | 包含的提取次数 |
|---|---|---|
| 入门 | $29 | 500 |
| 成长 | $79 | 5,000 |
| 规模 | $199 | 50,000 |
入门指南
- 获取 API 密钥,请访问 pagebolt.dev/pricing。
- 发送 POST 请求 到
/extract,并提供目标 URL(以及可选参数)。 - 在你的 AI 代理中使用返回的 Markdown——无需 HTML 解析。
免费开始,每月 100 次提取(无需信用卡)。
你的 AI 代理现在拥有一条直接从 URL 到干净、适合 LLM 使用的内容的管道。没有噪音,只有它所需的数据。