セットアップ
コピー
npm install @mendable/firecrawl-js @google/genai
コピー
FIRECRAWL_API_KEY=your_firecrawl_key
GEMINI_API_KEY=your_gemini_key
注意: Node < 20 を使用している場合は、dotenvをインストールし、コードにimport 'dotenv/config'を追加してください。
スクレイピング + 要約
コピー
import FirecrawlApp from '@mendable/firecrawl-js';
import { GoogleGenAI } from '@google/genai';
const firecrawl = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY });
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const scrapeResult = await firecrawl.scrape('https://firecrawl.dev', {
formats: ['markdown']
});
console.log('Scraped content length:', scrapeResult.markdown?.length);
const response = await ai.models.generateContent({
model: 'gemini-2.5-flash',
contents: `Summarize: ${scrapeResult.markdown}`,
});
console.log('Summary:', response.text);
コンテンツ分析
コピー
import FirecrawlApp from '@mendable/firecrawl-js';
import { GoogleGenAI } from '@google/genai';
const firecrawl = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY });
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const scrapeResult = await firecrawl.scrape('https://news.ycombinator.com/', {
formats: ['markdown']
});
console.log('Scraped content length:', scrapeResult.markdown?.length);
const chat = ai.chats.create({
model: 'gemini-2.5-flash'
});
// Hacker Newsのトップ3の記事を取得
const result1 = await chat.sendMessage({
message: `Based on this website content from Hacker News, what are the top 3 stories right now?\n\n${scrapeResult.markdown}`
});
console.log('Top 3 Stories:', result1.text);
// Hacker Newsの4番目と5番目の記事を取得
const result2 = await chat.sendMessage({
message: `Now, what are the 4th and 5th top stories on Hacker News from the same content?`
});
console.log('4th and 5th Stories:', result2.text);
構造化抽出
コピー
import FirecrawlApp from '@mendable/firecrawl-js';
import { GoogleGenAI, Type } from '@google/genai';
const firecrawl = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY });
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const scrapeResult = await firecrawl.scrape('https://stripe.com', {
formats: ['markdown']
});
console.log('Scraped content length:', scrapeResult.markdown?.length);
const response = await ai.models.generateContent({
model: 'gemini-2.5-flash',
contents: `Extract company information: ${scrapeResult.markdown}`,
config: {
responseMimeType: 'application/json',
responseSchema: {
type: Type.OBJECT,
properties: {
name: { type: Type.STRING },
industry: { type: Type.STRING },
description: { type: Type.STRING },
products: {
type: Type.ARRAY,
items: { type: Type.STRING }
}
},
propertyOrdering: ['name', 'industry', 'description', 'products']
}
}
});
console.log('Extracted company info:', response?.text);

