mirror of
https://github.com/mendableai/firecrawl.git
synced 2024-11-16 19:58:08 +08:00
29 lines
683 B
TypeScript
29 lines
683 B
TypeScript
import FirecrawlApp from "@mendable/firecrawl-js";
|
|
import { z } from "zod";
|
|
|
|
async function a() {
|
|
const app = new FirecrawlApp({
|
|
apiKey: "fc-YOUR_API_KEY",
|
|
});
|
|
|
|
// Define schema to extract contents into
|
|
const schema = z.object({
|
|
top: z
|
|
.array(
|
|
z.object({
|
|
title: z.string(),
|
|
points: z.number(),
|
|
by: z.string(),
|
|
commentsURL: z.string(),
|
|
})
|
|
)
|
|
.length(5)
|
|
.describe("Top 5 stories on Hacker News"),
|
|
});
|
|
const scrapeResult = await app.scrapeUrl("https://firecrawl.dev", {
|
|
extractorOptions: { extractionSchema: schema },
|
|
});
|
|
console.log(scrapeResult.data["llm_extraction"]);
|
|
}
|
|
a();
|