跳到正文

CrawlForge Team工程团队

阅读时长 9 分钟

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

Cursor IDE 擅长推理你的代码,但它看不到实时的网页。通过 Cursor 的 Model Context Protocol 集成 接入 CrawlForge,Composer 即可获得 31 个抓取工具——无需 Python 脚本、无需 curl、无需离开编辑器。

Json
// ~/.cursor/mcp.json
{
  "mcpServers": {
    "crawlforge": {
      "command": "crawlforge-mcp-server",
      "env": { "CRAWLFORGE_API_KEY": "cf_live_your_key" }
    }
  }
}

本指南逐步讲解如何在 Cursor IDE 中配置网页抓取,并提供可运行的示例,涵盖研究、结构化提取和竞争对手监控。

目录

为什么要在 Cursor 内部抓取?

Cursor Composer 把 MCP tools 当作一等公民的动作:它为任务挑选合适的工具、传入带类型的参数,并把结果回填到对话中。当你通过 CrawlForge 在 Cursor IDE 中抓取网站时,提取出的数据立即可供 Cursor 用来生成测试、编写 TypeScript 接口或更新仪表盘。无需复制粘贴,也无需切换上下文。

如果你已经在用 Cursor rules 来塑造 Composer 的行为,MCP tools 可以无缝衔接——rules 描述如何编码,工具则暴露 Composer 能做什么。

前置条件

  • Cursor IDE 0.42+ —— 从 cursor.com 下载
  • Node.js 18+ —— 用 node --version 检查
  • CrawlForge 账号 —— 在 crawlforge.dev/signup 免费注册

第 1 步:安装 MCP server

Bash
npm install -g crawlforge-mcp-server

确认它在你的 PATH 中:

Bash
which crawlforge-mcp-server
# /usr/local/bin/crawlforge-mcp-server

第 2 步:配置 Cursor 的 MCP 设置

Cursor 从 ~/.cursor/mcp.json 读取 MCP server。如果该文件不存在就创建它:

Bash
mkdir -p ~/.cursor
touch ~/.cursor/mcp.json

粘贴以下配置(替换为你的密钥):

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

在 Windows 上,该文件位于 %USERPROFILE%\.cursor\mcp.json,命令应为 crawlforge-mcp-server.cmd。

第 3 步:重启并验证

  1. 完全退出 Cursor(macOS 上按 Cmd+Q)。
  2. 重新打开项目。
  3. 进入 Settings -> Features -> MCP。你应当看到 crawlforge 旁有一个绿点,并列出 31 个工具。

如果 server 显示为红色或工具列表为空,请跳到 故障排查。

第 4 步:在 Composer 中完成你的第一次抓取

打开 Composer(Cmd+I)并粘贴:

Use CrawlForge to fetch https://news.ycombinator.com and list the top 5 story titles.

Cursor 会调用 fetch_url(1 credit)并显示响应。当你批准该工具调用后,Composer 会解析 HTML 并返回一份干净的列表。

完整示例:构建竞争对手价格追踪器

假设你想追踪某个竞争对手 SaaS 的价格变化。打开 Composer 并粘贴:

Use scrape_structured to pull pricing from https://competitor.example.com/pricing. Fields: plan (h3), price (.price), features (ul li). Then generate a TypeScript type for the response.

Cursor 会带上你的选择器发起一次 scrape_structured 调用,返回 JSON,并在下一个编辑器代码块中生成这段 TypeScript:

Typescript
// types/competitor-pricing.ts
export interface CompetitorPricingTier {
  plan: string;
  price: string;
  features: string[];
}

export interface CompetitorPricingResponse {
  data: CompetitorPricingTier[];
  scraped_at: string;
}

// lib/fetch-competitor-pricing.ts
import { CompetitorPricingResponse } from '@/types/competitor-pricing';

export async function fetchCompetitorPricing(): Promise<CompetitorPricingResponse> {
  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://competitor.example.com/pricing',
      selectors: {
        plan: '.pricing-card h3',
        price: '.pricing-card .price',
        features: '.pricing-card ul li',
      },
    }),
  });

  if (!response.ok) {
    throw new Error(`Scrape failed: ${response.statusText}`);
  }

  return response.json();
}

总成本:每次运行 2 credits。用 Vercel Cron 或 GitHub Actions 定时执行,你就拥有了一个免费层的价格追踪器。

工作流:用抓取结果编写代码

真正的威力在于把抓取到的数据喂给 Cursor 的代码生成。经过验证的模式:

  • 从实时 API 生成类型:"Fetch https://api.example.com/users, then generate a Zod schema matching the response."
  • 从真实页面生成测试夹具:"Scrape the top 3 articles from Hacker News and save them as JSON fixtures in tests/fixtures/."
  • 文档提取:"Use extract_content on the React docs for useState, then write an idiomatic example that matches."
  • 竞争对手功能对齐:"Use map_site on competitor.com and flag any URL patterns we do not have in our own sitemap."

每种模式每次运行 1-5 credits,并让你始终留在 Cursor 内部。

credits 成本汇总

操作工具Credits
获取 HTMLfetch_url1
干净文本extract_text1
可读文章extract_content2
CSS 选择器提取scrape_structured2
站点地图发现map_site2
网页搜索search_web5
带点击的 SPAscrape_with_actions5
反爬绕过stealth_mode5

故障排查

Cursor 设置中工具列表为空 —— Cursor 会缓存 MCP 配置。彻底退出(Cmd+Q)后再重新打开。检查 ~/.cursor/logs/ 中是否有解析错误。

"Command not found: crawlforge-mcp-server" —— npm 的全局 bin 不在 Cursor 的 PATH 中。在 mcp.json 中设置绝对路径来修复:"command": "/usr/local/bin/crawlforge-mcp-server"。

每次调用都返回 401 —— API key 缺失或仍是占位符。用以下命令验证:curl -H "Authorization: Bearer $CRAWLFORGE_API_KEY" https://crawlforge.dev/api/v1/credits/balance。

Cursor 在每次工具调用时都要求批准 —— 这是预期的默认行为。如果你希望 Composer 静默执行抓取,可在 MCP 设置中启用 "Auto-approve for trusted servers"。

Composer 忽略了 MCP 工具 —— 明确提示它:"Use CrawlForge's scrape_structured tool to..."。Cursor 有时会默认使用其内置的网页抓取,而后者能力较弱。

后续步骤

在 crawlforge.dev/signup 免费开始,赠送 1,000 credits。

亲自试一试——无需注册

在 Playground 中探索全部 31 个 CrawlForge 抓取与提取工具,然后免费开始,获取 1,000 credits。

1,000 免费 credits • 一次性 • 无需信用卡

标签

  • Cursor-IDE
  • web-scraping
  • MCP
  • tutorial
  • Composer
  • developer-tools
  • AI-agents

关于作者

CrawlForge Team

工程团队

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

邮件订阅

及时获取最新洞察

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

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

FAQ

常见问题

01Cursor IDE 会在哪里查找 MCP server 配置?

Cursor 在 macOS 和 Linux 上从 ~/.cursor/mcp.json 读取 MCP 配置,在 Windows 上从 %USERPROFILE%\\.cursor\\mcp.json 读取。更改后需要完全重启(Cmd+Q 后再打开)Cursor 才能识别。

02Cursor Composer 能自动运行 CrawlForge 工具吗?

可以。在 Settings > Features > MCP 中为受信任的服务器启用自动批准。之后 Composer 会调用 fetch_url、scrape_structured 等 CrawlForge 工具,而无需逐次弹出确认对话框,非常适合迭代式工作流。

03这与 Cursor Rules 指南有什么区别?

Cursor Rules 控制 Composer 如何编写代码(风格、框架、文件约定)。像 CrawlForge 这样的 MCP tools 则增加新能力——网页抓取、结构化提取、deep research。你通常两者都需要:用 rules 塑造输出,用 MCP tools 扩展 Composer 的能力。

04Cursor 在免费计划上支持 MCP tools 吗?

MCP 集成在所有 Cursor 计划上都可用,包括免费计划。只有在你需要高级模型时才需付费购买 Cursor Pro。CrawlForge 也有免费层(一次性 1,000 credits,无需绑卡),因此你可以零成本试用整套技术栈。

05我可以在包含多个项目的 monorepo 中使用 Cursor MCP tools 吗?

可以——MCP 配置对你的用户配置全局生效,而非按项目区分。在 Cursor 中打开的所有项目都能访问同一套 CrawlForge 工具。如需针对特定项目覆盖配置,可在仓库根目录添加 .cursor/mcp.json,Cursor 会将其与全局配置合并。

继续阅读

相关文章

教程

10 分钟

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

用 Claude Code 和 CrawlForge MCP 从你的终端抓取任何网站。抓取页面、提取数据并绕过反爬虫,全程不到 2 分钟。本指南涵盖从零开始的安装配置、常用工具选择与多个可直接复用的实战抓取示例。

教程

10 分钟

如何在 VS Code 中用 GitHub Copilot agent 抓取网站

为 VS Code 中的 GitHub Copilot agent 添加 web scraping 能力。配置 CrawlForge MCP,让 Copilot 能按需获取、提取并研究实时网页数据。本指南涵盖 mcp.json 配置、工具授权与实战示例。