通过MCP工具让Cursor Agent能访问JS渲染、Cloudflare防护或登录墙后的页面,获取实时数据而非过期缓存。
本文最初发布于 Zenrows 博客。原文地址:https://www.zenrows.com/blog/scrape-protected-sites-cursor
本指南演示如何将 Zenrows MCP 添加到 Cursor,使你的 agent 能够访问 Cursor 内置 Web 访问无法触及的受保护页面、JavaScript 渲染页面和最近更新的页面。你需要 Node.js v18+、一个 Zenrows API key 以及已安装的 Cursor。
安装过程只需一个 JSON 配置文件加一次重启。随后提供三个工作流来验证其在真实站点上的效果。
前置条件
Node.js v18 或更高版本。运行 node --version 确认。
Zenrows API key,来源:app.zenrows.com
三类场景会打破 Cursor 默认使用的缓存快照方式。
JavaScript 渲染的页面。 Cursor 获取的是 HTML 壳文件,运行时才加载的数据会丢失。
Bot 防护站点。 处于 Cloudflare、登录墙或反 Bot 系统背后的页面会阻止请求并返回一个缓存片段,且不会暴露任何错误。
最近更新的页面。 文档、定价或 API 参考在过去几小时内发生的变化。缓存副本可能已经是几天前的版本了。
这种失败通常是静默的。你的 agent 返回了内容,只是并非页面实际包含的内容。
mkdir -p ~/.cursor && cat > ~/.cursor/mcp.json << 'EOF'
{
"mcpServers": {
"zenrows": {
"command": "npx",
"args": ["-y", "@zenrows/mcp"],
"env": {
"ZENROWS_API_KEY": "your_api_key_here"
}
}
}
}
EOF
在 Windows 上,打开 File Explorer 中的 %USERPROFILE%\.cursor\,创建 mcp.json,然后粘贴同样的 JSON。
在打开 Cursor 之前运行此命令。末尾的逗号或缺失的括号会导致配置加载静默失败:
node -e "JSON.parse(require('fs').readFileSync(require('os').homedir()+'/.cursor/mcp.json','utf8')); console.log('JSON valid')"
输出 JSON valid 表示一切正常。这里的任何错误都意味着文件存在语法问题。
打开 Cursor → 左下角的齿轮图标 → 搜索 "MCP" → Tools & MCPs → Home MCP Servers。看到 zenrows 旁边有绿色圆点且显示 37 tools enabled 即为成功。
在 macOS 上,使用 ⌘Q 完全退出而非关闭窗口——MCP 服务器进程在启动时会读取你的 API key,所以关闭窗口是不够的。
将以下内容粘贴到 Cursor 的 agent 中:
Use the Zenrows MCP scrape tool to fetch https://www.scrapingcourse.com/antibot-challenge
and return the content as clean Markdown.
Do not use your built-in web browsing. Only use the Zenrows scrape tool.
Cursor 内置的浏览功能会返回该 URL 的挑战拦截页面。Zenrows 会清除反 Bot 挑战并以干净的 Markdown 形式返回其背后的页面内容。
Use the Zenrows MCP scrape tool to fetch https://www.scrapingcourse.com/javascript-rendering
and extract a structured JSON object containing the first 5 products with their name and price.
Do not use your built-in web browsing.
产品是动态加载的。普通的 HTTP 请求会返回空网格。Zenrows 先渲染页面,然后 agent 从 #product-grid 容器中解析出产品。
预期的输出格式:
[
{ "name": "Product Name", "price": "$XX.XX" },
...
]
这个例子结合了两个层级的抓取和代码生成。Home Depot 的分类列表包含产品名称和价格,而 SKU 和型号仅存在于各个产品详情页,因此 agent 必须抓取两个层级并将数据合并。
Use the Zenrows MCP scrape tool to fetch
https://www.homedepot.com/b/Tools-Woodworking-Tools/N-5yc1vZc2gv?catStyle=ShowProducts
and return the first 5 products as structured JSON with name and price. Then fetch each
product's individual page and add its SKU and model number.
Set proxy country to US. Do not use your built-in web browsing.
Then write a TypeScript function that fetches and displays product details for a given
product name.
proxy_country: US 将请求路由通过美国 IP,使零售商返回其正常目录,而不受你运行 Cursor 所在地区的影响。
Agent 在两个页面层级上返回结构化 JSON:
{
"products": [
{
"name": "Gorilla 4 fl. oz. Wood Glue",
"price": "$3.98",
"sku": "1003827526",
"model_number": "62020"
},
{
"name": "DEWALT 20V MAX XR Cordless Brushless Fixed Base Compact Router (Tool Only)",
"price": "$249.00",
"sku": "1004095707",
"model_number": "DCW600B"
}
]
}
然后它会生成一个具有如下签名的 TypeScript 函数:
export async function fetchAndDisplayProductDetails(
productName: string,
apiKey = process.env.ZENROWS_API_KEY ?? ""
): Promise<HomeDepotProductDetails | null>
export ZENROWS_API_KEY="your_api_key_here"
npm run build
npm run homedepot -- "Gorilla 4 fl. oz. Wood Glue"
结果保存到 data/homedepot-products.json。
两者均可在 Cursor 中使用。公开页面且追求速度和简单性时使用 Firecrawl。页面受保护、JavaScript 渲染或属于高批量工作流时使用 Zenrows。
完整对比:Zenrows vs Firecrawl
添加配置后 Zenrows MCP 没有出现
完全重启 Cursor(macOS 上用 ⌘Q)。使用步骤 2 中的命令校验你的 JSON。
Agent 响应中报 401 错误
mcp.json 中的 ZENROWS_API_KEY 错误或仍为占位符。对照你 Zenrows 账户中的有效 key 逐一检查,保存,完全退出 Cursor 后重新打开。
macOS 上的 EACCES 错误
sudo chown -R $(id -u):$(id -g) ~/.npm
更偏好托管 MCP 服务器而非 npx?
在 Cursor 的远程 MCP 配置中使用 https://mcp.zenrows.com/mcp,并将你的 API key 作为 Bearer token 传入。
Zenrows MCP 概览:完整工具参考
Cursor 集成文档:参考配置
Zenrows MCP 安装指南:适用于 Claude Desktop 及其他 agent
OpenAI Agents SDK + Zenrows:以代码方式注册工具而非运行 MCP server