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/",
crawlerOptions: new CrawlUrlsRequestCrawlerOptions
{
Limit = 1,
},
pageOptions: new CrawlUrlsRequestPageOptions
{
IncludeHtml = true,
OnlyMainContent = true,
},
cancellationToken: cancellationToken);
Console.WriteLine($"Success: {response.Success}");
Console.WriteLine($"Id: {response.Id}");
Console.WriteLine($"Url: {response.Url}");
GetCrawlStatusResponse? statusResponse = null;
while (!cancellationToken.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
statusResponse = await api.Crawl.GetCrawlStatusAsync(
jobId: response.Id!,
cancellationToken: cancellationToken);
if (statusResponse.Status == "completed")
{
break;
}
}
var index = 0;
foreach (var data in statusResponse.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}");
}