Documentation Index
Fetch the complete documentation index at: https://docs.firecrawl.dev/llms.txt
Use this file to discover all available pages before exploring further.
- Deno 1.40+ 或 Deno 2
- 一个 Firecrawl API 密钥 — 免费获取
创建 main.ts:
import Firecrawl from "npm:@mendable/firecrawl-js";
const firecrawl = new Firecrawl({
apiKey: Deno.env.get("FIRECRAWL_API_KEY"),
});
添加一个 /search 路由,用于进行网页搜索,并返回包含完整页面内容的结果。
Deno.serve(async (req) => {
const url = new URL(req.url);
if (req.method === "POST" && url.pathname === "/search") {
const { query } = await req.json();
const results = await firecrawl.search(query, { limit: 5 });
return Response.json(results);
}
return new Response("Not found", { status: 404 });
});
添加 /scrape 路由,从任意 URL 提取干净的 Markdown。
if (req.method === "POST" && url.pathname === "/scrape") {
const { url: targetUrl } = await req.json();
const result = await firecrawl.scrape(targetUrl);
return Response.json(result);
}
添加 /interact 路由以控制实时浏览器会话——点击按钮、填写表单并提取动态内容。
if (req.method === "POST" && url.pathname === "/interact") {
const result = await firecrawl.scrape("https://www.amazon.com", {
formats: ["markdown"],
});
const scrapeId = result.metadata?.scrapeId;
await firecrawl.interact(scrapeId, {
prompt: "Search for iPhone 16 Pro Max",
});
const response = await firecrawl.interact(scrapeId, {
prompt: "Click on the first result and tell me the price",
});
console.log(response.output);
await firecrawl.stopInteraction(scrapeId);
return Response.json({ output: response.output });
}
FIRECRAWL_API_KEY=fc-YOUR-API-KEY deno run --allow-net --allow-env main.ts
安装 Deno Deploy CLI (deployctl) 并部署:
deployctl deploy --project=my-scraper main.ts
在 Deno Deploy 的 Dashboard 中或通过 CLI 设置环境变量:
deployctl env set FIRECRAWL_API_KEY=fc-YOUR-API-KEY --project=my-scraper
curl -X POST https://my-scraper.deno.dev/search \
-H "Content-Type: application/json" \
-d '{"query": "firecrawl web scraping"}'
抓取文档
所有抓取选项,包括 formats、actions 和代理
Node SDK 参考
完整的 SDK 参考,涵盖爬取、map、batch scrape 等功能