本页内容
Cursor IDE 擅长推理你的代码,但它看不到实时的网页。通过 Cursor 的 Model Context Protocol 集成 接入 CrawlForge,Composer 即可获得 26 个抓取工具——无需 Python 脚本、无需 curl、无需离开编辑器。
// ~/.cursor/mcp.json
{
"mcpServers": {
"crawlforge": {
"command": "crawlforge-mcp-server",
"env": { "CRAWLFORGE_API_KEY": "cf_live_your_key" }
}
}
}本指南逐步讲解如何在 Cursor IDE 中配置网页抓取,并提供可运行的示例,涵盖研究、结构化提取和竞争对手监控。
目录
- 为什么要在 Cursor 内部抓取?
- 前置条件
- 第 1 步:安装 MCP server
- 第 2 步:配置 Cursor 的 MCP 设置
- 第 3 步:重启并验证
- 第 4 步:在 Composer 中完成你的第一次抓取
- 完整示例:构建竞争对手价格追踪器
- 工作流:用抓取结果编写代码
- 故障排查
- 常见问题
为什么要在 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
npm install -g crawlforge-mcp-server确认它在你的 PATH 中:
which crawlforge-mcp-server
# /usr/local/bin/crawlforge-mcp-server第 2 步:配置 Cursor 的 MCP 设置
Cursor 从 ~/.cursor/mcp.json 读取 MCP server。如果该文件不存在就创建它:
mkdir -p ~/.cursor
touch ~/.cursor/mcp.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 步:重启并验证
- 完全退出 Cursor(macOS 上按
Cmd+Q)。 - 重新打开项目。
- 进入 Settings -> Features -> MCP。你应当看到
crawlforge旁有一个绿点,并列出 26 个工具。
如果 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:
// 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_contenton the React docs foruseState, then write an idiomatic example that matches." - 竞争对手功能对齐:"Use
map_siteon competitor.com and flag any URL patterns we do not have in our own sitemap."
每种模式每次运行 1-5 credits,并让你始终留在 Cursor 内部。
credits 成本汇总
| 操作 | 工具 | Credits |
|---|---|---|
| 获取 HTML | fetch_url | 1 |
| 干净文本 | extract_text | 1 |
| 可读文章 | extract_content | 2 |
| CSS 选择器提取 | scrape_structured | 2 |
| 站点地图发现 | map_site | 2 |
| 网页搜索 | search_web | 5 |
| 带点击的 SPA | scrape_with_actions | 5 |
| 反爬绕过 | stealth_mode | 5 |
故障排查
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 有时会默认使用其内置的网页抓取,而后者能力较弱。
后续步骤
- 阅读 Cursor rules 指南,优化 Composer 的抓取行为
- 浏览 26 个工具总览,看看还能自动化什么
- 查看 入门文档 了解 API 参考和 credit 定价
- 在 Firecrawl 替代方案 比较各家供应商
在 crawlforge.dev/signup 免费开始,赠送 1,000 credits。
亲自试一试——无需注册
在 Playground 中运行 CrawlForge 的 27 个抓取与提取工具中的任意一个,然后免费开始,获取 1,000 credits。
1,000 免费 credits • 每月补充 • 无需信用卡
标签
及时获取最新洞察
将教程、产品更新与 Web 抓取技巧直接发送到你的收件箱。
拒绝垃圾邮件,随时可取消订阅。