use firecrawl::Firecrawl;
#[tokio::main]
async fn main() {
// Inicializa Firecrawl con la clave de la API
let api_key = "YOUR_API_KEY";
let api_url = "https://api.firecrawl.dev";
let app = Firecrawl::new(api_key, api_url).expect("No se pudo inicializar Firecrawl");
// Define el esquema en el que se extraerá el contenido
let json_schema = json!({
"type": "object",
"properties": {
"top": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {"type": "string"},
"points": {"type": "number"},
"by": {"type": "string"},
"commentsURL": {"type": "string"}
},
"required": ["title", "points", "by", "commentsURL"]
},
"minItems": 5,
"maxItems": 5,
"description": "Top 5 stories on Hacker News"
}
},
"required": ["top"]
});
let llm_extraction_params = json!({
"extractorOptions": {
"extractionSchema": json_schema,
"mode": "llm-extraction"
},
"pageOptions": {
"onlyMainContent": true
}
});
let llm_extraction_result = app
.scrape_url("https://news.ycombinator.com", Some(llm_extraction_params))
.await;
match llm_extraction_result {
Ok(data) => println!("Resultado de la extracción con LLM:\n{}", data["llm_extraction"]),
Err(e) => eprintln!("Error en la extracción con LLM: {}", e),
}
}