CrawlForge
首页Playground应用场景集成价格文档博客
如何用 Claude Code 抓取网站(2026 指南)
Tutorials
返回博客
教程

如何用 Claude Code 抓取网站(2026 指南)

C
CrawlForge Team
工程团队
2026年4月14日
阅读时长 10 分钟

本页内容

Claude Code 可以编辑文件、执行 shell 命令并编写测试,但它自身无法抓取实时网页。把它接入 CrawlForge MCP,便能获得 20 个直接从终端运行的 scraping 工具。

Bash
npm install -g crawlforge-mcp-server
npx crawlforge-setup  # paste your API key
# Now in Claude Code:
# > Fetch https://news.ycombinator.com and list the top 5 stories

本指南向你展示如何用 CrawlForge MCP 通过 Claude Code 抓取网站,从安装到 stealth 模式绕过。下面每个代码块都是可执行的。

目录

  • 问题所在:Claude Code 无法抓取 URL
  • 前置条件
  • 步骤 1:安装 CrawlForge MCP
  • 步骤 2:获取你的 API key
  • 步骤 3:在 Claude Code 中注册 MCP server
  • 步骤 4:验证连接
  • 步骤 5:你的第一次抓取
  • 完整可用示例:抓取一个定价页面
  • 进阶:抓取 JavaScript 渲染的网站
  • 故障排查
  • 常见问题

问题所在:Claude Code 无法抓取 URL

默认情况下,Claude Code 没有网络访问权限。让它"读一下这篇博客文章",它会告诉你无法打开 URL。Claude Desktop 中内置的 WebFetch 助手确实存在,但它有限制、有速率上限,并且经常被 Cloudflare、Akamai 等边缘防护拦截。

CrawlForge MCP 通过把 20 个 scraping 工具——fetch_url、extract_content、scrape_structured、stealth_mode、deep_research 等等——暴露为 Model Context Protocol 工具来解决这个问题,Claude Code 可以像调用任何其他函数一样调用它们。关于协议本身的更多背景,请参阅我们的 完整 MCP web scraping 指南。

前置条件

  • Node.js 18+ —— 用 node --version 检查
  • Claude Code —— 用 npm install -g @anthropic-ai/claude-code 安装
  • 一个 CrawlForge 账户 —— 在 crawlforge.dev/signup 免费注册(含 1,000 credits,无需信用卡)

步骤 1:安装 CrawlForge MCP

Bash
npm install -g crawlforge-mcp-server

验证安装:

Bash
crawlforge-mcp-server --version
# crawlforge-mcp-server 4.8.1

步骤 2:获取你的 API key

  1. 前往 crawlforge.dev/signup 并创建账户。
  2. 打开 crawlforge.dev/dashboard/api-keys 的控制台。
  3. 复制 key:它以 cf_live_ 开头。

步骤 3:在 Claude Code 中注册 MCP server

最快的方式是配置向导:

Bash
npx crawlforge-setup

它会把正确的条目写入 ~/.config/claude-code/mcp.json(Linux/macOS)或 %APPDATA%\claude-code\mcp.json(Windows)。

如果你更喜欢手动配置,把下面这段加入你的 Claude Code MCP 配置:

Json
{
  "mcpServers": {
    "crawlforge": {
      "command": "crawlforge-mcp-server",
      "env": {
        "CRAWLFORGE_API_KEY": "cf_live_your_key_here"
      }
    }
  }
}

重启 Claude Code,让它检测到新服务器。

步骤 4:验证连接

打开 Claude Code 并运行:

/mcp

你应当看到 crawlforge 列在其中,显示为已连接、提供 26 个可用工具。如果没有,请前往 故障排查。

步骤 5:你的第一次抓取

把这个提示粘贴到 Claude Code 中:

Fetch https://news.ycombinator.com using CrawlForge and give me the top 5 story titles with their URLs as a JSON array.

Claude Code 会调用 fetch_url(1 credit),解析 HTML 并返回类似这样的内容:

Json
[
  { "title": "Show HN: My side project", "url": "https://example.com/post/1" },
  { "title": "Why X is changing Y", "url": "https://example.com/post/2" }
]

就是这样。你已经开始抓取了。

完整可用示例:抓取一个定价页面

这里有一个真实的任务:提取一个 SaaS 网站的定价层级。粘贴这个提示:

Use scrape_structured to extract pricing from https://crawlforge.dev/pricing. Return an array of { plan, price, credits, features[] }.

在底层,Claude Code 会构建一个像这样的请求:

Typescript
// What Claude Code sends to CrawlForge via MCP
const response = await fetch('https://crawlforge.dev/api/v1/tools/scrape_structured', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.CRAWLFORGE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://crawlforge.dev/pricing',
    selectors: {
      plan: '.pricing-card h3',
      price: '.pricing-card .price',
      credits: '.pricing-card .credits',
      features: '.pricing-card ul li',
    },
  }),
});

const data = await response.json();
console.log(data.plan); // ['Free', 'Hobby', 'Professional', 'Business']

成本:2 credits。把它和本地运行一个无头浏览器相比:零基础设施、无需调试 Puppeteer、没有 Cloudflare 的轮盘赌。

进阶:抓取 JavaScript 渲染的网站

有些网站通过客户端 React 渲染定价或产品数据。fetch_url 返回的是水合前的 HTML 骨架,会错过这些数据。改用 scrape_with_actions(5 credits):

Typescript
// Prompt Claude Code with this, and it generates the call
const payload = {
  url: 'https://app.example.com/dashboard',
  actions: [
    { type: 'wait', selector: '.data-grid', timeout: 5000 },
    { type: 'click', selector: 'button.load-more' },
    { type: 'wait', timeout: 1500 },
  ],
  formats: ['json', 'markdown'],
};

const result = await fetch('https://crawlforge.dev/api/v1/tools/scrape_with_actions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.CRAWLFORGE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(payload),
}).then(r => r.json());

对于受 Cloudflare 和 Akamai 保护的网站,使用 stealth_mode(同样 5 credits)。我们在 stealth 模式深度解析 中介绍了指纹轮换的取舍。

工具速查参考

工具Credits何时使用
fetch_url1静态 HTML,自行解析
extract_text1文章页面的干净、可读文本
extract_content2类可读性的主内容提取
scrape_structured2CSS 选择器映射到带类型字段
search_web5你还不知道 URL
scrape_with_actions5SPA 需要点击、等待、滚动
stealth_mode5反爬虫系统(Cloudflare、DataDome)
deep_research10带引用的多来源研究

完整列表见我们的 26 个工具总览。

故障排查

"MCP server failed to start" —— 确认 crawlforge-mcp-server 在你的 PATH 中。运行 which crawlforge-mcp-server。如果为空,重新全局安装:npm install -g crawlforge-mcp-server。

"Unauthorized" 或 401 错误 —— 你的 API key 缺失或格式不对。它必须以 cf_live_ 开头。在你的 shell 中重新导出:export CRAWLFORGE_API_KEY="cf_live_..." 然后重启 Claude Code。

"Insufficient credits" —— 在 crawlforge.dev/dashboard/usage 查看用量。Free 层 = 1,000 credits/月。升级到 Hobby($19/月)可获得 25,000。

/mcp 中工具列表为空 —— MCP 配置没有被读取。在 macOS 上文件位于 ~/Library/Application Support/claude-code/mcp.json。Linux:~/.config/claude-code/mcp.json。Windows:%APPDATA%\claude-code\mcp.json。

每次 fetch 都遇到 Cloudflare 403 —— 把 fetch_url 换成 stealth_mode。如果仍被拦截,目标站点使用了服务端 JA3/JA4 指纹识别;请带上该 URL 在 GitHub 上提一个 issue。

常见问题

快速答案请查看下方的常见问题部分。

后续步骤

  • 阅读 CrawlForge 快速上手 获取五个可复制粘贴的示例
  • 探索 快速上手文档 获取完整的 API 参考
  • 在 Claude Desktop vs Claude Code 中对比 MCP 客户端
  • 在 Firecrawl 替代方案 中评估其他选择

在 crawlforge.dev/signup 用 1,000 credits 免费开始。无需信用卡。

亲自试一试——无需注册

在 Playground 中运行 CrawlForge 的 27 个抓取与提取工具中的任意一个,然后免费开始,获取 1,000 credits。

1,000 免费 credits • 每月补充 • 无需信用卡

标签

Claude-Codeweb-scrapingMCPtutorialCLIAI-agentsgetting-started

关于作者

C

CrawlForge Team

工程团队

我们正在打造功能最全面的 Web 抓取 MCP server。我们开发的工具帮助开发者为 AI 应用提取、分析和转换 Web 数据。

及时获取最新洞察

将教程、产品更新与 Web 抓取技巧直接发送到你的收件箱。

拒绝垃圾邮件,随时可取消订阅。

付诸实践

在任意 URL 上测试 CrawlForge 的工具——免费,无需注册。

本页内容

Frequently Asked Questions

没有 CrawlForge,Claude Code 能抓取网站吗?+

无法可靠地做到。Claude Code 没有内置网络访问,而 Claude Desktop 的 WebFetch 助手有速率上限,并会被大多数反爬虫系统拦截。CrawlForge MCP 添加了 20 个专用 scraping 工具,能处理静态 HTML、JavaScript 渲染的页面以及受 Cloudflare 保护的网站。

用 Claude Code 抓取的成本是多少?+

CrawlForge 采用 credits 模型:基础抓取 1 credit,结构化提取 2 credits,搜索 5,stealth 模式 5,深度研究 10。免费账户每月获得 1,000 credits,无需信用卡。Hobby 套餐($19/月)含 25,000 credits。

为什么 Claude Code 抓取某些 URL 时会得到 403 错误?+

受 Cloudflare、DataDome 或 Akamai 保护的网站通过 TLS 指纹识别和 JavaScript 挑战来拦截通用 HTTP 客户端。把 fetch_url(1 credit)换成 stealth_mode(5 credits),它会轮换浏览器指纹并自动解决这些挑战。

CrawlForge MCP 在 Windows 上能配合 Claude Code 使用吗?+

可以。通过 npm 安装,运行 npx crawlforge-setup,配置就会落在 %APPDATA%\\claude-code\\mcp.json。Node.js 18+ 是唯一的系统要求。Windows 用户应当从 PowerShell 或 Windows Terminal 运行配置命令,以获得更顺畅的体验。

fetch_url 和 scrape_with_actions 有什么区别?+

fetch_url 通过一次快速的 HTTP 请求返回原始 HTML(1 credit)。scrape_with_actions 会启动一个无头浏览器,执行点击/等待/滚动,然后捕获水合后的 DOM(5 credits)。静态页面用 fetch_url,只有在需要 JavaScript 渲染时才用 scrape_with_actions。

相关文章

CrawlForge MCP 快速上手:60 秒从零开始 web scraping
Tutorials

CrawlForge MCP 快速上手:60 秒从零开始 web scraping

安装 CrawlForge MCP,获取免费 API key,并在一分钟内运行你的第一次 web scrape。五个可复制粘贴的示例,适用于 Claude 和 Cursor。

C
CrawlForge Team
|
3月31日
|
3 分钟
用 Claude 进行网页抓取:完整指南(2026)
Tutorials

用 Claude 进行网页抓取:完整指南(2026)

2026 年用 Claude 抓取网页:把 CrawlForge MCP 接入 Claude Desktop、Claude Code 或 API,即可抓取任何网站——无需编写抓取代码。

C
CrawlForge Team
|
6月9日
|
12 分钟
如何在 Cursor IDE 中使用 CrawlForge MCP 抓取网站
Tutorials

如何在 Cursor IDE 中使用 CrawlForge MCP 抓取网站

把 Cursor IDE 变成网页抓取工作站。接入 CrawlForge MCP,无需离开编辑器即可从任意站点提取结构化数据。

C
CrawlForge Team
|
4月14日
|
9 分钟

页脚

CrawlForge

面向 AI Agent 的企业级网页抓取。27 个专业 MCP 工具,专为构建智能系统的现代开发者而设计。

产品

  • 功能
  • Playground
  • 价格
  • 应用场景
  • 集成
  • 替代方案
  • 更新日志

资源

  • 快速上手
  • API 参考
  • 模板
  • 指南
  • 博客
  • 术语表
  • 常见问题
  • 网站地图

开发者

  • MCP 协议
  • Claude Desktop
  • Cursor IDE
  • LangChain
  • LlamaIndex

公司

  • 关于我们
  • 联系我们
  • 隐私政策
  • 服务条款
  • 可接受使用政策
  • Cookie

保持更新

获取新工具和新功能的最新动态。

基于 Next.js 和 MCP 协议构建

© 2025-2026 CrawlForge。保留所有权利。