Documentation Index
Fetch the complete documentation index at: https://firecrawl-mog-search-exclude-include-domains.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
- Node.js 18+
- 一个 Firecrawl API 密钥 — 免费获取
npm install express @mendable/firecrawl-js
将你的 API 密钥添加到 .env 文件中:
FIRECRAWL_API_KEY=fc-YOUR-API-KEY
import express from "express";
import Firecrawl from "@mendable/firecrawl-js";
const app = express();
app.use(express.json());
const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });
app.post("/search", async (req, res) => {
try {
const { query } = req.body;
const results = await firecrawl.search(query, { limit: 5 });
res.json(results);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(3000, () => console.log("Server running on port 3000"));
app.post("/scrape", async (req, res) => {
try {
const { url } = req.body;
const result = await firecrawl.scrape(url);
res.json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
使用 interact 控制实时浏览器会话,可点击按钮、填写表单并提取动态内容。
app.post("/interact", async (req, res) => {
try {
const { url } = req.body;
const result = await firecrawl.scrape(url, { 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' });
await firecrawl.stopInteraction(scrapeId);
res.json({ output: response.output });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
curl -X POST http://localhost:3000/search \
-H "Content-Type: application/json" \
-d '{"query": "firecrawl web scraping"}'
抓取文档
包含所有抓取选项,如 formats、actions 和代理
Node SDK 参考
完整的 SDK 参考,涵盖爬取、map、batch 抓取 等