import FirecrawlApp, { ExtractResponse } from '@mendable/firecrawl-js';
const app = new FirecrawlApp({apiKey: "fc-YOUR_API_KEY"});
// 使用 schema 和提示词从网站提取:
const extractResult = await app.extract(['https://example-forum.com/topic/123'], {
prompt: "提取此论坛线程中的所有用户评论。",
schema: {
type: "object",
properties: {
comments: {
type: "array",
items: {
type: "object",
properties: {
author: {type: "string"},
comment_text: {type: "string"}
},
required: ["author", "comment_text"]
}
}
},
required: ["comments"]
},
agent: {
model: 'FIRE-1'
}
}) as ExtractResponse;
if (!extractResult.success) {
throw new Error(`提取失败:${extractResult.error}`)
}
console.log(extractResult)