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.
bun add @mendable/firecrawl-js
.envにAPI keyを追加します:
FIRECRAWL_API_KEY=fc-YOUR-API-KEY
Bun には組み込みの HTTP サーバーがあります。index.ts を作成します:
import Firecrawl from "@mendable/firecrawl-js";
const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });
Bun.serve({
port: 3000,
async fetch(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 });
},
});
console.log("Server running on port 3000");
実行:
同じサーバーに /scrape ルートを追加します:
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 { url: targetUrl } = await req.json();
const result = await firecrawl.scrape(targetUrl, { 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);
return Response.json({ output: response.output });
}
スタンドアロンのBunスクリプトでFirecrawlを使うには、次のようにします。
import Firecrawl from "@mendable/firecrawl-js";
const app = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });
const results = await app.search("firecrawl web scraping", { limit: 5 });
console.log(results);
スクレイピング ドキュメント
フォーマット、アクション、プロキシを含む、スクレイピングのオプション全般
Search ドキュメント
Web を検索してページ全体のコンテンツを取得
Interact ドキュメント
クリックやフォーム入力を行い、動的コンテンツを抽出
Node SDK リファレンス
クロール、map、バッチスクレイプなどを含む SDK の完全なリファレンス