> ## 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.

# Gemini

> Firecrawl を Google の Gemini AI と統合して、Web スクレイピングと AI ワークフローに活用する

Web データを活用する AI アプリケーション向けに、Firecrawl を Google の Gemini と統合します。

<div id="setup">
  ## セットアップ
</div>

```bash theme={null}
npm install firecrawl @google/genai
```

「.env」ファイルを作成:

```bash theme={null}
FIRECRAWL_API_KEY=your_firecrawl_key
GEMINI_API_KEY=your_gemini_key
```

> **注意:** Node \< 20 を使用している場合は、`dotenv` をインストールし、コードに `import 'dotenv/config'` を追加してください。

<div id="scrape-summarize">
  ## スクレイピング + 要約
</div>

この例では、Web サイトをスクレイピングし、そのコンテンツを Gemini で要約するというシンプルなワークフローを紹介します。

```typescript theme={null}
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);
```

<div id="content-analysis">
  ## コンテンツ分析
</div>

この例では、Gemini のマルチターン会話機能を使って Web サイトのコンテンツを分析する方法を示します。

```typescript theme={null}
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);
```

<div id="structured-extraction">
  ## 構造化抽出
</div>

この例では、スクレイピングしたWeb サイトのコンテンツから、Gemini の JSONモード を使って構造化データを抽出する方法を示します。

```typescript theme={null}
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 のドキュメント](https://ai.google.dev/docs)を参照してください。
