Web データを活用する AI アプリケーション向けに、Firecrawl を Google の Gemini と統合します。
セットアップ#
npm install firecrawl @google/genai「.env」ファイルを作成:
FIRECRAWL_API_KEY=your_firecrawl_keyGEMINI_API_KEY=your_gemini_key注意: Node < 20 を使用している場合は、
dotenvをインストールし、コードにimport 'dotenv/config'を追加してください。
スクレイピング + 要約#
この例では、Web サイトをスクレイピングし、そのコンテンツを Gemini で要約するというシンプルなワークフローを紹介します。
import { Firecrawl } from 'firecrawl';import { GoogleGenAI } from '@google/genai';const firecrawl = new Firecrawl({ 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);コンテンツ分析#
この例では、Gemini のマルチターン会話機能を使って Web サイトのコンテンツを分析する方法を示します。
import { Firecrawl } from 'firecrawl';import { GoogleGenAI } from '@google/genai';const firecrawl = new Firecrawl({ 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);構造化抽出#
この例では、スクレイピングしたWeb サイトのコンテンツから、Gemini の JSONモード を使って構造化データを抽出する方法を示します。
import { Firecrawl } from 'firecrawl';import { GoogleGenAI, Type } from '@google/genai';const firecrawl = new Firecrawl({ 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);より多くの例については、Gemini のドキュメントを参照してください。

