Skip to content

Commit 0840f52

Browse files
committed
Added firecrawl example docs
1 parent cdcfc81 commit 0840f52

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: "Crawl a URL using Firecrawl"
3+
sidebarTitle: "Firecrawl URL crawl"
4+
description: "This example demonstrates how to crawl a URL using Firecrawl with Trigger.dev."
5+
---
6+
7+
## Overview
8+
9+
Firecrawl is a tool for crawling websites and extracting clean markdown that's structured in an LLM-ready format.
10+
11+
Here are two examples of how to use Firecrawl with Trigger.dev:
12+
13+
## Prerequisites
14+
15+
- A project with [Trigger.dev initialized](/quick-start)
16+
- A [Firecrawl](https://firecrawl.dev/) account
17+
18+
## Example 1: crawl an entire website with Firecrawl
19+
20+
This task crawls a website and returns the `crawlResult` object. You can set the `limit` parameter to control the number of URLs that are crawled.
21+
22+
```ts trigger/firecrawl-url-crawl.ts
23+
import FirecrawlApp from "@mendable/firecrawl-js";
24+
import { task } from "@trigger.dev/sdk/v3";
25+
26+
// Initialize the Firecrawl client with your API key
27+
const firecrawlClient = new FirecrawlApp({
28+
apiKey: process.env.FIRECRAWL_API_KEY, // Get this from your Firecrawl dashboard
29+
});
30+
31+
export const firecrawlCrawl = task({
32+
id: "firecrawl-crawl",
33+
run: async (payload: { url: string }) => {
34+
const { url } = payload;
35+
36+
// Crawl: scrapes all the URLs of a web page and return content in LLM-ready format
37+
const crawlResult = await firecrawlClient.crawlUrl(url, {
38+
limit: 100, // Limit the number of URLs to crawl
39+
scrapeOptions: {
40+
formats: ["markdown", "html"],
41+
},
42+
});
43+
44+
if (!crawlResult.success) {
45+
throw new Error(`Failed to crawl: ${crawlResult.error}`);
46+
}
47+
48+
return {
49+
data: crawlResult,
50+
};
51+
},
52+
});
53+
```
54+
55+
### Testing your task
56+
57+
You can test your task by triggering it from the Trigger.dev dashboard.
58+
59+
```json
60+
"url": "<url-to-crawl>" // Replace with the URL you want to crawl
61+
```
62+
63+
## Example 2: scrape a single URL with Firecrawl
64+
65+
This task scrapes a single URL and returns the `scrapeResult` object.
66+
67+
```ts trigger/firecrawl-url-scrape.ts
68+
import FirecrawlApp, { ScrapeResponse } from "@mendable/firecrawl-js";
69+
import { task } from "@trigger.dev/sdk/v3";
70+
71+
// Initialize the Firecrawl client with your API key
72+
const firecrawlClient = new FirecrawlApp({
73+
apiKey: process.env.FIRECRAWL_API_KEY, // Get this from your Firecrawl dashboard
74+
});
75+
76+
export const firecrawlScrape = task({
77+
id: "firecrawl-scrape",
78+
run: async (payload: { url: string }) => {
79+
const { url } = payload;
80+
81+
// Scrape: scrapes a URL and get its content in LLM-ready format (markdown, structured data via LLM Extract, screenshot, html)
82+
const scrapeResult = (await firecrawlClient.scrapeUrl(url, {
83+
formats: ["markdown", "html"],
84+
})) as ScrapeResponse;
85+
86+
if (!scrapeResult.success) {
87+
throw new Error(`Failed to scrape: ${scrapeResult.error}`);
88+
}
89+
90+
return {
91+
data: scrapeResult,
92+
};
93+
},
94+
});
95+
```
96+
97+
### Testing your task
98+
99+
You can test your task by triggering it from the Trigger.dev dashboard.
100+
101+
```json
102+
"url": "<url-to-scrape>" // Replace with the URL you want to scrape
103+
```

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@
370370
"guides/examples/dall-e3-generate-image",
371371
"guides/examples/deepgram-transcribe-audio",
372372
"guides/examples/ffmpeg-video-processing",
373+
"guides/examples/firecrawl-url-crawl",
373374
"guides/examples/open-ai-with-retrying",
374375
"guides/examples/pdf-to-image",
375376
"guides/examples/puppeteer",

0 commit comments

Comments
 (0)