Gemini
Usa Firecrawl con Gemini de Google para scraping web y flujos de trabajo con IA
Integra Firecrawl con Gemini de Google para aplicaciones de IA impulsadas por datos de la web.
npm install firecrawl @google/genaiCrea el archivo .env:
FIRECRAWL_API_KEY=your_firecrawl_key
GEMINI_API_KEY=your_gemini_keyNota: Si usas Node < 20, instala
dotenvy añadeimport 'dotenv/config'a tu código.
Este ejemplo muestra un flujo de trabajo sencillo: scrapear un sitio web y resumir su contenido con 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);Este ejemplo muestra cómo analizar el contenido de un sitio web usando las capacidades de conversación multiturno de 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://news.ycombinator.com/', {
formats: ['markdown']
});
console.log('Scraped content length:', scrapeResult.markdown?.length);
const chat = ai.chats.create({
model: 'gemini-2.5-flash'
});
// Solicitar las 3 historias principales de Hacker News
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);
// Solicitar las historias 4.ª y 5.ª de Hacker News
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);Este ejemplo muestra cómo extraer datos estructurados usando el modo JSON de Gemini a partir de contenido extraído de sitios web.
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('Longitud del contenido scrapeado:', scrapeResult.markdown?.length);
const response = await ai.models.generateContent({
model: 'gemini-2.5-flash',
contents: `Extrae información de la empresa: ${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('Información de la empresa extraída:', response?.text);Para más ejemplos, consulta la documentación de Gemini.
Was this page helpful?Suggest editsRaise issue