Skip to content

Commit e81b2a7

Browse files
authored
Firecrawl example docs (#1438)
* Added firecrawl example docs * Added Firecrawl and scrape hn to the intro page table
1 parent cdcfc81 commit e81b2a7

File tree

3 files changed

+121
-15
lines changed

3 files changed

+121
-15
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/guides/introduction.mdx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,23 @@ Get set up fast using our detailed walk-through guides.
3737

3838
Tasks you can copy and paste to get started with Trigger.dev. They can all be extended and customized to fit your needs.
3939

40-
| Example task | Description |
41-
| :---------------------------------------------------------------------------- | :----------------------------------------------------------------------------- |
42-
| [DALL·E 3 image generation](/guides/examples/dall-e3-generate-image) | Use OpenAI's GPT-4o and DALL·E 3 to generate an image and text. |
43-
| [Deepgram audio transcription](/guides/examples/deepgram-transcribe-audio) | Transcribe audio using Deepgram's speech recognition API. |
44-
| [FFmpeg video processing](/guides/examples/ffmpeg-video-processing) | Use FFmpeg to process a video in various ways and save it to Cloudflare R2. |
45-
| [OpenAI with retrying](/guides/examples/open-ai-with-retrying) | Create a reusable OpenAI task with custom retry options. |
46-
| [PDF to image](/guides/examples/pdf-to-image) | Use `MuPDF` to turn a PDF into images and save them to Cloudflare R2. |
47-
| [React to PDF](/guides/examples/react-pdf) | Use `react-pdf` to generate a PDF and save it to Cloudflare R2. |
48-
| [Puppeteer](/guides/examples/puppeteer) | Use Puppeteer to generate a PDF or scrape a webpage. |
49-
| [Resend email sequence](/guides/examples/resend-email-sequence) | Send a sequence of emails over several days using Resend with Trigger.dev. |
50-
| [Sentry error tracking](/guides/examples/sentry-error-tracking) | Automatically send errors to Sentry from your tasks. |
51-
| [Sharp image processing](/guides/examples/sharp-image-processing) | Use Sharp to process an image and save it to Cloudflare R2. |
52-
| [Supabase database operations](/guides/examples/supabase-database-operations) | Run basic CRUD operations on a table in a Supabase database using Trigger.dev. |
53-
| [Supabase Storage upload](/guides/examples/supabase-storage-upload) | Download a video from a URL and upload it to Supabase Storage using S3. |
54-
| [Vercel AI SDK](/guides/examples/vercel-ai-sdk) | Use Vercel AI SDK to generate text using OpenAI. |
40+
| Example task | Description |
41+
| :---------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
42+
| [DALL·E 3 image generation](/guides/examples/dall-e3-generate-image) | Use OpenAI's GPT-4o and DALL·E 3 to generate an image and text. |
43+
| [Deepgram audio transcription](/guides/examples/deepgram-transcribe-audio) | Transcribe audio using Deepgram's speech recognition API. |
44+
| [FFmpeg video processing](/guides/examples/ffmpeg-video-processing) | Use FFmpeg to process a video in various ways and save it to Cloudflare R2. |
45+
| [Firecrawl URL crawl](/guides/examples/firecrawl-url-crawl) | Learn how to use Firecrawl to crawl a URL and return LLM-ready markdown. |
46+
| [OpenAI with retrying](/guides/examples/open-ai-with-retrying) | Create a reusable OpenAI task with custom retry options. |
47+
| [PDF to image](/guides/examples/pdf-to-image) | Use `MuPDF` to turn a PDF into images and save them to Cloudflare R2. |
48+
| [React to PDF](/guides/examples/react-pdf) | Use `react-pdf` to generate a PDF and save it to Cloudflare R2. |
49+
| [Puppeteer](/guides/examples/puppeteer) | Use Puppeteer to generate a PDF or scrape a webpage. |
50+
| [Resend email sequence](/guides/examples/resend-email-sequence) | Send a sequence of emails over several days using Resend with Trigger.dev. |
51+
| [Scrape Hacker News](/guides/examples/scrape-hacker-news) | Scrape Hacker News using BrowserBase and Puppeteer, summarize the articles with ChatGPT and send an email of the summary every weekday using Resend. |
52+
| [Sentry error tracking](/guides/examples/sentry-error-tracking) | Automatically send errors to Sentry from your tasks. |
53+
| [Sharp image processing](/guides/examples/sharp-image-processing) | Use Sharp to process an image and save it to Cloudflare R2. |
54+
| [Supabase database operations](/guides/examples/supabase-database-operations) | Run basic CRUD operations on a table in a Supabase database using Trigger.dev. |
55+
| [Supabase Storage upload](/guides/examples/supabase-storage-upload) | Download a video from a URL and upload it to Supabase Storage using S3. |
56+
| [Vercel AI SDK](/guides/examples/vercel-ai-sdk) | Use Vercel AI SDK to generate text using OpenAI. |
5557

5658
<Note>
5759
If you would like to see a guide for your framework, or an example task for your use case, please

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)