Crawl

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using var api = new FirecrawlApp(apiKey);
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(5));
var cancellationToken = cancellationTokenSource.Token;

var response = await api.Crawling.CrawlUrlsAsync(
    url: "https://docs.firecrawl.dev/",
    limit: 3,
    scrapeOptions: new CrawlUrlsRequestScrapeOptions
    {
        //IncludeHtml = true,
        OnlyMainContent = true,
    },
    cancellationToken: cancellationToken);

Console.WriteLine($"JobId: {response.JobId}");


var jobResponse = await api.Crawling.WaitJobAsync(
    jobId: response.JobId!,
    cancellationToken: cancellationToken);

var index = 0;
foreach (var data in jobResponse.Data ?? [])
{

    var fileInfo = new FileInfo($"output{++index}.md");
    await File.WriteAllTextAsync(fileInfo.FullName, data.Markdown, cancellationToken);
    Console.WriteLine($"Output file: {new Uri(fileInfo.FullName).AbsoluteUri}");
}