本页内容
Model Context Protocol(MCP)从根本上改变了 AI 助手与网络交互的方式。这份全面的指南涵盖了开发者关于 MCP web scraping 需要了解的一切 —— 从基础概念到进阶技巧。
第一部分:理解 MCP
什么是 Model Context Protocol?
MCP(Model Context Protocol)是一个由 Anthropic 开发的开放标准,让 Claude 等 AI 助手能够连接到外部工具和数据源。可以把它看作一个通用适配器,让 AI 模型能够使用专用工具。
┌─────────────┐ ┌───────────────┐ ┌──────────────┐
│ Claude │ ←──→ │ MCP Server │ ←──→ │ External │
│ (AI Model) │ │ (CrawlForge) │ │ Resources │
└─────────────┘ └───────────────┘ └──────────────┘
↑
MCP Protocol
(JSON-RPC over stdio)
为什么 MCP 对 web scraping 至关重要
在 MCP 出现之前,AI 助手无法可靠地访问网页数据:
| 方法 | 问题 |
|---|---|
| 训练数据 | 过时,存在知识截止 |
| RAG(检索) | 仅限于已索引的文档 |
| 函数调用 | 需要自定义实现 |
| 浏览器插件 | 不稳定,存在安全顾虑 |
MCP 通过以下方式解决了这些问题:
- 标准化接口 —— 一套协议适配所有工具
- 实时数据 —— 来自任意来源的最新信息
- 工具可组合性 —— 无缝组合多个工具
- 安全模型 —— 对外部资源的受控访问
MCP 的工作原理
MCP 采用基于 JSON-RPC 的客户端-服务器架构:
1. 服务器发现
{
"mcpServers": {
"crawlforge": {
"command": "npx",
"args": ["crawlforge-mcp-server"]
}
}
}2. 工具注册
{
"tools": [
{
"name": "fetch_url",
"description": "Fetch content from a URL",
"inputSchema": {
"type": "object",
"properties": {
"url": { "type": "string", "format": "uri" }
},
"required": ["url"]
}
}
]
}3. 工具调用
{
"method": "tools/call",
"params": {
"name": "fetch_url",
"arguments": {
"url": "https://example.com"
}
}
}4. 响应
{
"result": {
"content": "<html>...",
"status": 200,
"headers": {...}
}
}第二部分:MCP web scraping 生态
MCP 抓取服务器
有多个 MCP server 提供 web scraping 能力:
| 服务器 | 工具数 | 侧重点 |
|---|---|---|
| CrawlForge | 20 | 全面的抓取、研究、隐身 |
| Firecrawl | ~5 | 基础抓取与爬取 |
| Browser MCP | ~3 | 浏览器自动化 |
| Fetch MCP | 1 | 简单的 HTTP 请求 |
为什么 CrawlForge 领先
CrawlForge 专为 MCP 而构建,拥有最广泛的工具覆盖:
CrawlForge: ████████████████████ 26 tools
Firecrawl: █████ 5 tools
Browser: ███ 3 tools
Fetch: █ 1 tool
第三部分:CrawlForge 的 26 个工具详解
基础抓取(1-2 credits)
1. fetch_url(1 credit)
web scraping 的基石 —— 从任意 URL 抓取原始 HTML。
// Usage:
"Fetch https://example.com"
// Returns:
{
"html": "<html>...",
"status": 200,
"headers": {...},
"timing": { "total": 523 }
}何时使用: 任何抓取任务的起点。永远先试它。
2. extract_text(1 credit)
提取干净的文本内容,移除 HTML 标签、脚本和样式。
// Usage:
"Extract text from https://example.com/article"
// Returns:
{
"text": "Article headline\n\nFirst paragraph...",
"wordCount": 1247,
"readingTime": 5
}何时使用: 博客文章、报道、文档等需要可读文本的场景。
3. extract_links(1 credit)
发现页面上的所有链接,可选过滤。
// Usage:
"Extract all links from https://example.com"
// With filtering:
{
"url": "https://example.com",
"filter_external": true // Internal links only
}
// Returns:
{
"links": [
{ "href": "/about", "text": "About Us" },
{ "href": "/products", "text": "Products" }
],
"total": 45
}何时使用: 站点探索、查找待抓取的页面、构建站点地图。
4. extract_metadata(1 credit)
提取 SEO 元数据:标题、描述、Open Graph、JSON-LD。
// Usage:
"Get metadata from https://example.com"
// Returns:
{
"title": "Example Site - Homepage",
"description": "Welcome to Example...",
"openGraph": {
"title": "Example Site",
"image": "https://example.com/og.png"
},
"jsonLd": [...]
}何时使用: SEO 分析、内容预览、结构化数据提取。
结构化提取(2-3 credits)
5. scrape_structured(2 credits)
使用 CSS 选择器提取特定数据。
// Usage:
{
"url": "https://example.com/products",
"selectors": {
"title": "h1.product-title",
"price": "span.price",
"description": ".product-description"
}
}
// Returns:
{
"data": {
"title": "Product Name",
"price": "$99.99",
"description": "Product description..."
}
}何时使用: 电商抓取、结构化数据、已知的页面布局。
6. extract_content(2 credits)
智能的文章提取(类似 Readability)。
// Usage:
"Extract the main content from https://blog.example.com/post"
// Returns:
{
"title": "Blog Post Title",
"author": "John Smith",
"publishedDate": "2026-01-15",
"content": "Clean article text...",
"images": ["..."],
"readingTime": 7
}何时使用: 新闻报道、博客文章、编辑类内容。
7. map_site(2 credits)
发现站点结构并生成站点地图。
// Usage:
{
"url": "https://example.com",
"max_urls": 1000,
"include_sitemap": true
}
// Returns:
{
"pages": [
{ "url": "/", "title": "Home", "depth": 0 },
{ "url": "/about", "title": "About", "depth": 1 },
...
],
"structure": {
"/": ["/about", "/products", "/blog"],
"/products": ["/products/1", "/products/2"]
}
}何时使用: 站点审计、爬取规划、内容发现。
8. analyze_content(3 credits)
NLP 分析:语言、情感、主题、实体。
// Usage:
"Analyze this content: [text]"
// Returns:
{
"language": "en",
"sentiment": { "score": 0.7, "label": "positive" },
"topics": ["technology", "AI", "automation"],
"entities": [
{ "text": "OpenAI", "type": "organization" },
{ "text": "GPT-4", "type": "product" }
],
"readability": { "grade": 12, "score": 45 }
}何时使用: 内容分析、情感跟踪、主题提取。
进阶抓取(4-5 credits)
9. process_document(2 credits)
处理 PDF 和文档。
// Usage:
{
"source": "https://example.com/report.pdf",
"sourceType": "pdf_url"
}
// Returns:
{
"text": "Extracted PDF text...",
"pages": 15,
"metadata": {
"author": "...",
"created": "..."
}
}何时使用: 研究论文、报告、文档类 PDF。
10. summarize_content(4 credits)
AI 驱动的摘要生成。
// Usage:
"Summarize this article: [long text]"
// Returns:
{
"summary": "Concise summary...",
"keyPoints": [
"Point 1",
"Point 2",
"Point 3"
],
"wordReduction": "85%"
}何时使用: 长文档、研究综合、内容摘要。
11. crawl_deep(4 credits)
可配置深度的多页面爬取。
// Usage:
{
"url": "https://example.com",
"max_depth": 3,
"max_pages": 100,
"include_patterns": ["/blog/*"],
"exclude_patterns": ["/admin/*"]
}
// Returns:
{
"pages": [...], // All crawled pages
"stats": {
"total": 87,
"successful": 85,
"failed": 2
}
}何时使用: 全站抓取、内容聚合、归档。
12. batch_scrape(5 credits)
并行抓取多个 URL。
// Usage:
{
"urls": [
"https://example1.com",
"https://example2.com",
// ... up to 50 URLs
],
"maxConcurrency": 10
}
// Returns:
{
"results": [
{ "url": "...", "success": true, "data": {...} },
...
],
"stats": { "successful": 48, "failed": 2 }
}何时使用: 多个已知 URL、竞品监控、价格跟踪。
13. scrape_with_actions(5 credits)
带操作的浏览器自动化。
// Usage:
{
"url": "https://example.com/app",
"actions": [
{ "type": "wait", "selector": ".content" },
{ "type": "click", "selector": "#load-more" },
{ "type": "wait", "timeout": 2000 },
{ "type": "scroll", "selector": "body" },
{ "type": "screenshot" }
]
}
// Returns:
{
"finalContent": "...",
"screenshots": ["base64..."],
"actionsExecuted": 5
}何时使用: SPA、无限滚动、动态内容、需要登录的场景。
14. search_web(5 credits)
Google 搜索集成。
// Usage:
{
"query": "web scraping best practices 2026",
"limit": 10,
"site": "github.com" // Optional site filter
}
// Returns:
{
"results": [
{
"title": "...",
"url": "...",
"snippet": "..."
},
...
]
}何时使用: 发现、查找来源、研究的起点。
专用工具(3-10 credits)
15. stealth_mode(5 credits)
反检测绕过(详见隐身模式指南)。
// Usage:
{
"operation": "create_context",
"stealthConfig": {
"level": "advanced",
"hideWebDriver": true,
"randomizeFingerprint": true,
"simulateHumanBehavior": true
}
}何时使用: 受保护的站点、绕过 Cloudflare、规避反爬虫。
16. track_changes(3 credits)
内容监控与变更检测。
// Usage:
{
"url": "https://example.com/pricing",
"operation": "create_baseline",
"monitoringOptions": {
"interval": 86400000, // Daily
"notificationThreshold": "moderate"
}
}
// Returns (on change):
{
"changes": [
{
"type": "text_change",
"path": ".pricing-tier-1",
"before": "$19/mo",
"after": "$29/mo",
"significance": "major"
}
]
}何时使用: 价格监控、竞品跟踪、内容更新。
17. localization(2 credits)
地理定向抓取。
// Usage:
{
"operation": "configure_country",
"countryCode": "GB",
"language": "en-GB"
}
// Then scrape to get UK-specific content/pricing何时使用: 区域定价、本地化内容、地理限制数据。
18. extract_structured(3 credits)
LLM 驱动、由 schema 引导的提取,并支持 CSS 选择器回退。
// Usage:
{
"url": "https://example.com/product/123",
"schema": {
"type": "object",
"properties": {
"title": { "type": "string" },
"price": { "type": "number" }
},
"required": ["title"]
},
"prompt": "Extract the product name and price"
}何时使用: 当你想要符合某个 schema 的类型化输出,又不想手写选择器时。
19. generate_llms_txt(5 credits)
分析一个站点并生成符合标准的 llms.txt 和 llms-full.txt 文件。
// Usage:
{
"url": "https://example.com",
"format": "both",
"complianceLevel": "standard",
"outputOptions": {
"organizationName": "Example Inc.",
"contactEmail": "ai@example.com"
}
}何时使用: 为你的网站发布 AI 交互指南。
20. deep_research(10 credits)
全面的多来源研究(详见深度研究指南)。
// Usage:
{
"topic": "quantum computing commercialization",
"maxUrls": 50,
"enableSourceVerification": true,
"enableConflictDetection": true
}
// Returns:
{
"synthesis": "Comprehensive analysis...",
"sources": [...],
"conflicts": [...],
"citations": [...]
}何时使用: 研究项目、尽职调查、市场分析。
第四部分:集成指南
Claude Code 设置
# 1. Install CrawlForge MCP server
npm install -g crawlforge-mcp-server
# 2. Run setup wizard
npx crawlforge-setup
# 3. Add to Claude Code
claude
> /mcp add crawlforge npx crawlforge-mcp-server
# 4. Verify
> /mcp list
# Should show: crawlforge (26 tools)Claude Desktop 设置
编辑你的 Claude Desktop 配置文件:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"crawlforge": {
"command": "npx",
"args": ["crawlforge-mcp-server"],
"env": {
"CRAWLFORGE_API_KEY": "cf_live_your_key_here"
}
}
}
}自定义应用集成
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
const transport = new StdioClientTransport({
command: "npx",
args: ["crawlforge-mcp-server"],
env: {
CRAWLFORGE_API_KEY: process.env.CRAWLFORGE_API_KEY
}
});
const client = new Client({
name: "my-app",
version: "1.0.0"
});
await client.connect(transport);
// List available tools
const tools = await client.listTools();
console.log(`Available tools: ${tools.tools.length}`);
// Call a tool
const result = await client.callTool({
name: "fetch_url",
arguments: {
url: "https://example.com"
}
});第五部分:最佳实践
credits 优化
| 目标 | 高成本 | 高效 |
|---|---|---|
| 检查页面是否存在 | deep_research (10) | fetch_url (1) |
| 获取文章正文 | scrape_with_actions (5) | extract_content (2) |
| 查找竞品 URL | search_web × 10 (50) | extract_links (1) |
| 抓取 20 个产品页面 | fetch_url × 20 (20) | batch_scrape (5) |
错误处理
// Always handle failures gracefully
try {
const result = await fetchUrl(url);
if (result.status >= 400) {
// Try with stealth mode
return await stealthMode(url);
}
return result;
} catch (error) {
// Log and retry with exponential backoff
await sleep(retryDelay * attempt);
return retry(url, attempt + 1);
}速率限制
尊重目标站点:
// Good: Reasonable delays
for (const url of urls) {
await scrape(url);
await sleep(1000 + Math.random() * 2000); // 1-3s delay
}
// Better: Use batch_scrape with built-in rate limiting
await batchScrape(urls, { delayBetweenRequests: 1500 });缓存
不要重复抓取同一个 URL:
const cache = new Map<string, ScrapedContent>();
async function smartScrape(url: string) {
if (cache.has(url)) {
return cache.get(url);
}
const result = await fetchUrl(url);
cache.set(url, result);
return result;
}第六部分:MCP 抓取的未来
新兴趋势
- AI 原生提取 —— LLM 直接解析非结构化 HTML
- 自愈型 scraper —— AI 自动适应站点变化
- 语义搜索 —— 用自然语言查询抓取到的数据
- 跨站分析 —— AI 在多个来源之间关联信息
CrawlForge 路线图
2026 年即将推出:
- 实时监控 —— 即时的变更通知
- AI schema 生成 —— 自动生成提取模板
- 跨工具工作流 —— 智能地串联工具
- 增强隐私 —— 零知识抓取选项
快速上手
准备好开始 MCP web scraping 了吗?这是你的路径:
免费套餐(非常适合入门)
- 一次性 1,000 个试用 credits
- 全部 26 个工具可用
- 无需信用卡
# Quick start
npm install -g crawlforge-mcp-server
npx crawlforge-setup
# Visit: https://crawlforge.dev/signup1,000 个 credits 能做些什么
| 使用场景 | 工具 | Credits | 每月容量 |
|---|---|---|---|
| 基础抓取 | fetch_url | 1 | 1,000 个页面 |
| 文章提取 | extract_content | 2 | 500 篇文章 |
| 站点测绘 | map_site | 2 | 500 个站点 |
| 批量任务 | batch_scrape | 5 | 200 个批次(1 万个 URL) |
| 研究项目 | deep_research | 10 | 100 个主题 |
总结
MCP 彻底变革了面向 AI 应用的 web scraping。关键要点:
- MCP 是标准 —— 所有主流 AI 助手都支持它
- CrawlForge 凭借 26 个工具领先 —— 是替代方案的 4 倍
- 从简单入手 —— 在使用进阶工具前,先用 fetch_url(1 credit)
- 组合工具 —— 串联多个操作以构建强大的工作流
- 保持合规 —— 尊重 robots.txt 和速率限制
相关资源:
亲自试一试——无需注册
在 Playground 中运行 CrawlForge 的 27 个抓取与提取工具中的任意一个,然后免费开始,获取 1,000 credits。
1,000 免费 credits • 每月补充 • 无需信用卡
标签
及时获取最新洞察
将教程、产品更新与 Web 抓取技巧直接发送到你的收件箱。
拒绝垃圾邮件,随时可取消订阅。