Skip to content

Commit 79997c1

Browse files
committed
feat: add firecrawl scrape url overloads
1 parent f53d784 commit 79997c1

2 files changed

Lines changed: 86 additions & 7 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
namespace Firecrawl;
2+
3+
public partial class ScrapingClient
4+
{
5+
/// <summary>
6+
/// Scrape a single URL and optionally apply scrape options.
7+
/// </summary>
8+
/// <param name="url"></param>
9+
/// <param name="cancellationToken">The token to cancel the operation with</param>
10+
public Task<ScrapeResponse> ScrapeAndExtractFromUrlAsync(
11+
Uri url,
12+
CancellationToken cancellationToken = default)
13+
{
14+
ArgumentNullException.ThrowIfNull(url);
15+
16+
return ScrapeAndExtractFromUrlAsync(
17+
url: url.ToString(),
18+
cancellationToken: cancellationToken);
19+
}
20+
21+
/// <summary>
22+
/// Scrape a single URL and apply the provided scrape options.
23+
/// </summary>
24+
/// <param name="url"></param>
25+
/// <param name="options"></param>
26+
/// <param name="cancellationToken">The token to cancel the operation with</param>
27+
public Task<ScrapeResponse> ScrapeAndExtractFromUrlAsync(
28+
Uri url,
29+
ScrapeOptions options,
30+
CancellationToken cancellationToken = default)
31+
{
32+
ArgumentNullException.ThrowIfNull(url);
33+
34+
return ScrapeAndExtractFromUrlAsync(
35+
url: url.ToString(),
36+
options: options,
37+
cancellationToken: cancellationToken);
38+
}
39+
40+
/// <summary>
41+
/// Scrape a single URL and optionally apply scrape options.
42+
/// </summary>
43+
/// <param name="url"></param>
44+
/// <param name="cancellationToken">The token to cancel the operation with</param>
45+
public Task<ScrapeResponse> ScrapeAndExtractFromUrlAsync(
46+
string url,
47+
CancellationToken cancellationToken = default)
48+
{
49+
ArgumentException.ThrowIfNullOrWhiteSpace(url);
50+
51+
return ScrapeAndExtractFromUrlAsync(
52+
request: new AllOf<ScrapeAndExtractFromUrlRequest2, ScrapeOptions>(
53+
new ScrapeAndExtractFromUrlRequest2
54+
{
55+
Url = url,
56+
},
57+
new ScrapeOptions()),
58+
cancellationToken: cancellationToken);
59+
}
60+
61+
/// <summary>
62+
/// Scrape a single URL and apply the provided scrape options.
63+
/// </summary>
64+
/// <param name="url"></param>
65+
/// <param name="options"></param>
66+
/// <param name="cancellationToken">The token to cancel the operation with</param>
67+
public Task<ScrapeResponse> ScrapeAndExtractFromUrlAsync(
68+
string url,
69+
ScrapeOptions options,
70+
CancellationToken cancellationToken = default)
71+
{
72+
ArgumentException.ThrowIfNullOrWhiteSpace(url);
73+
ArgumentNullException.ThrowIfNull(options);
74+
75+
return ScrapeAndExtractFromUrlAsync(
76+
request: new AllOf<ScrapeAndExtractFromUrlRequest2, ScrapeOptions>(
77+
new ScrapeAndExtractFromUrlRequest2
78+
{
79+
Url = url,
80+
},
81+
options),
82+
cancellationToken: cancellationToken);
83+
}
84+
}

src/tests/IntegrationTests/Examples/Scrape.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@ public async Task Scrape()
1313
{
1414
using var client = GetAuthenticatedClient();
1515

16-
var response = await client.Scraping.ScrapeAndExtractFromUrlAsync(new AllOf<ScrapeAndExtractFromUrlRequest2, ScrapeOptions>
17-
{
18-
Value1 = new ScrapeAndExtractFromUrlRequest2
19-
{
20-
Url = "https://docs.firecrawl.dev/features/scrape",
21-
},
22-
});
16+
var response = await client.Scraping.ScrapeAndExtractFromUrlAsync(
17+
url: "https://docs.firecrawl.dev/features/scrape");
2318
response.Data.Should().NotBeNull();
2419
response.Data!.Markdown.Should().NotBeNullOrEmpty();
2520

0 commit comments

Comments
 (0)