pub struct Client { /* private fields */ }Expand description
Scrapfly API client. Cheap to Clone (the inner reqwest::Client is
Arc’d so all clones share one connection pool).
Implementations§
Source§impl Client
impl Client
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Start a new ClientBuilder.
Sourcepub fn cloud_browser_host(&self) -> &str
pub fn cloud_browser_host(&self) -> &str
Return the configured Cloud Browser host.
Sourcepub async fn verify_api_key(&self) -> Result<VerifyApiKeyResult, ScrapflyError>
pub async fn verify_api_key(&self) -> Result<VerifyApiKeyResult, ScrapflyError>
Verify the API key by hitting /account.
Sourcepub async fn account(&self) -> Result<AccountData, ScrapflyError>
pub async fn account(&self) -> Result<AccountData, ScrapflyError>
Fetch account info.
Sourcepub async fn classify(
&self,
req: &ClassifyRequest,
) -> Result<ClassifyResult, ScrapflyError>
pub async fn classify( &self, req: &ClassifyRequest, ) -> Result<ClassifyResult, ScrapflyError>
Classify an already-fetched HTTP response for anti-bot blocking.
Runs the same detection pipeline used by every live Scrapfly scrape against a response you already have (from your own proxy, cache, etc). 1 API credit per successful call. See https://scrapfly.io/docs/scrape-api/classify.
Sourcepub async fn get_monitoring_metrics(
&self,
opts: &MonitoringMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch aggregate monitoring metrics for the Web Scraping API.
Sourcepub async fn get_monitoring_target_metrics(
&self,
opts: &MonitoringTargetMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch per-target monitoring metrics for the Web Scraping API.
Sourcepub async fn get_screenshot_monitoring_metrics(
&self,
opts: &MonitoringMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_screenshot_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch aggregate monitoring metrics for the Screenshot API.
Sourcepub async fn get_screenshot_monitoring_target_metrics(
&self,
opts: &MonitoringTargetMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_screenshot_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch per-target monitoring metrics for the Screenshot API.
Sourcepub async fn get_extraction_monitoring_metrics(
&self,
opts: &MonitoringMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_extraction_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch aggregate monitoring metrics for the Extraction API.
Sourcepub async fn get_extraction_monitoring_target_metrics(
&self,
opts: &MonitoringTargetMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_extraction_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch per-target monitoring metrics for the Extraction API.
Sourcepub async fn get_crawler_monitoring_metrics(
&self,
opts: &MonitoringMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_crawler_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch aggregate monitoring metrics for the Crawler API.
Sourcepub async fn get_crawler_monitoring_target_metrics(
&self,
opts: &MonitoringTargetMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_crawler_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch per-target monitoring metrics for the Crawler API.
Sourcepub async fn get_browser_monitoring_metrics(
&self,
opts: &CloudBrowserMonitoringOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_browser_monitoring_metrics( &self, opts: &CloudBrowserMonitoringOptions, ) -> Result<Value, ScrapflyError>
Fetch aggregate monitoring metrics for the Cloud Browser API.
Sourcepub async fn get_browser_monitoring_timeseries(
&self,
opts: &CloudBrowserMonitoringOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_browser_monitoring_timeseries( &self, opts: &CloudBrowserMonitoringOptions, ) -> Result<Value, ScrapflyError>
Fetch monitoring time-series for the Cloud Browser API.
Sourcepub async fn scrape(
&self,
config: &ScrapeConfig,
) -> Result<ScrapeResult, ScrapflyError>
pub async fn scrape( &self, config: &ScrapeConfig, ) -> Result<ScrapeResult, ScrapflyError>
Scrape a URL.
Sourcepub fn concurrent_scrape<'a, I>(
&'a self,
configs: I,
concurrency_limit: usize,
) -> impl Stream<Item = Result<ScrapeResult, ScrapflyError>> + 'a
pub fn concurrent_scrape<'a, I>( &'a self, configs: I, concurrency_limit: usize, ) -> impl Stream<Item = Result<ScrapeResult, ScrapflyError>> + 'a
Concurrent-scrape stream. Emits results in completion order.
Sourcepub async fn scrape_batch(
&self,
configs: &[ScrapeConfig],
) -> Result<impl Stream<Item = (String, BatchOutcome)>, ScrapflyError>
pub async fn scrape_batch( &self, configs: &[ScrapeConfig], ) -> Result<impl Stream<Item = (String, BatchOutcome)>, ScrapflyError>
POST /scrape/batch: scrape up to 100 URLs and stream results
back as each scrape completes. Returns an async stream where
each item is (correlation_id, Result<ScrapeResult, ScrapflyError>).
Results arrive OUT OF ORDER — whichever scrape finishes first
is yielded first. Every ScrapeConfig MUST carry a unique
correlation_id; missing / duplicate values are caught
client-side before the request is sent.
Batch-level failures (plan gate, insufficient concurrency,
validation) surface as the outer Err(ScrapflyError) returned
from the await — the stream is only created after the
batch request succeeds.
Sourcepub async fn scrape_batch_with_options(
&self,
configs: &[ScrapeConfig],
opts: BatchOptions,
) -> Result<impl Stream<Item = (String, BatchOutcome)>, ScrapflyError>
pub async fn scrape_batch_with_options( &self, configs: &[ScrapeConfig], opts: BatchOptions, ) -> Result<impl Stream<Item = (String, BatchOutcome)>, ScrapflyError>
Like scrape_batch but with explicit BatchOptions
(msgpack wire format, etc.).
Sourcepub async fn scrape_proxified(
&self,
config: &ScrapeConfig,
) -> Result<Response, ScrapflyError>
pub async fn scrape_proxified( &self, config: &ScrapeConfig, ) -> Result<Response, ScrapflyError>
Scrape a URL with proxified_response=true, returning the raw
upstream reqwest::Response (target’s status, headers, body).
Unlike [scrape()], no JSON parsing occurs — the response body is
the target page’s raw content. Scrapfly metadata is available on
the X-Scrapfly-* response headers (Api-Cost, Content-Format,
Log, etc.).
Automatically forces proxified_response=true regardless of the
config’s field value.
Sourcepub async fn screenshot(
&self,
config: &ScreenshotConfig,
) -> Result<ScreenshotResult, ScrapflyError>
pub async fn screenshot( &self, config: &ScreenshotConfig, ) -> Result<ScreenshotResult, ScrapflyError>
Screenshot a URL.
Sourcepub async fn extract(
&self,
config: &ExtractionConfig,
) -> Result<ExtractionResult, ScrapflyError>
pub async fn extract( &self, config: &ExtractionConfig, ) -> Result<ExtractionResult, ScrapflyError>
Run AI extraction on a document.
Sourcepub async fn start_crawl(
&self,
config: &CrawlerConfig,
) -> Result<CrawlerStartResponse, ScrapflyError>
pub async fn start_crawl( &self, config: &CrawlerConfig, ) -> Result<CrawlerStartResponse, ScrapflyError>
Schedule a new crawler job.
Sourcepub async fn crawl_status(
&self,
uuid: &str,
) -> Result<CrawlerStatus, ScrapflyError>
pub async fn crawl_status( &self, uuid: &str, ) -> Result<CrawlerStatus, ScrapflyError>
Fetch crawler status.
Sourcepub async fn crawl_urls(
&self,
uuid: &str,
status_filter: Option<&str>,
page: u32,
per_page: u32,
) -> Result<CrawlerUrls, ScrapflyError>
pub async fn crawl_urls( &self, uuid: &str, status_filter: Option<&str>, page: u32, per_page: u32, ) -> Result<CrawlerUrls, ScrapflyError>
List crawled URLs (streaming text endpoint).
Sourcepub async fn crawl_contents_json(
&self,
uuid: &str,
format: CrawlerContentFormat,
limit: Option<u32>,
offset: Option<u32>,
) -> Result<CrawlerContents, ScrapflyError>
pub async fn crawl_contents_json( &self, uuid: &str, format: CrawlerContentFormat, limit: Option<u32>, offset: Option<u32>, ) -> Result<CrawlerContents, ScrapflyError>
Bulk GET /crawl/{uuid}/contents in JSON mode.
Sourcepub async fn crawl_contents_plain(
&self,
uuid: &str,
target_url: &str,
format: CrawlerContentFormat,
) -> Result<String, ScrapflyError>
pub async fn crawl_contents_plain( &self, uuid: &str, target_url: &str, format: CrawlerContentFormat, ) -> Result<String, ScrapflyError>
Plain single-URL GET /crawl/{uuid}/contents?plain=true.
Sourcepub async fn crawl_contents_batch(
&self,
uuid: &str,
urls: &[String],
formats: &[CrawlerContentFormat],
) -> Result<BTreeMap<String, BTreeMap<String, String>>, ScrapflyError>
pub async fn crawl_contents_batch( &self, uuid: &str, urls: &[String], formats: &[CrawlerContentFormat], ) -> Result<BTreeMap<String, BTreeMap<String, String>>, ScrapflyError>
Bulk-batch POST /crawl/{uuid}/contents/batch.
Returns url → format → content (multipart/related response).
Sourcepub async fn crawl_cancel(&self, uuid: &str) -> Result<(), ScrapflyError>
pub async fn crawl_cancel(&self, uuid: &str) -> Result<(), ScrapflyError>
Cancel a crawler job.
Sourcepub async fn crawl_artifact(
&self,
uuid: &str,
artifact_type: CrawlerArtifactType,
) -> Result<CrawlerArtifact, ScrapflyError>
pub async fn crawl_artifact( &self, uuid: &str, artifact_type: CrawlerArtifactType, ) -> Result<CrawlerArtifact, ScrapflyError>
Download a crawler artifact (WARC or HAR).
Source§impl Client
impl Client
Sourcepub fn cloud_browser_url(&self, config: &BrowserConfig) -> String
pub fn cloud_browser_url(&self, config: &BrowserConfig) -> String
Build the WebSocket URL for a new Cloud Browser session.
Sourcepub async fn cloud_browser_unblock(
&self,
config: &UnblockConfig,
) -> Result<UnblockResult, ScrapflyError>
pub async fn cloud_browser_unblock( &self, config: &UnblockConfig, ) -> Result<UnblockResult, ScrapflyError>
Call POST /unblock to bypass anti-bot protection.
Sourcepub async fn cloud_browser_extension_list(&self) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_extension_list(&self) -> Result<Value, ScrapflyError>
List browser extensions for the account.
Sourcepub async fn cloud_browser_extension_get(
&self,
extension_id: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_extension_get( &self, extension_id: &str, ) -> Result<Value, ScrapflyError>
Get details of a specific browser extension.
Sourcepub async fn cloud_browser_extension_upload(
&self,
file_path: &Path,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_extension_upload( &self, file_path: &Path, ) -> Result<Value, ScrapflyError>
Upload a browser extension from a local file (.zip or .crx).
Sourcepub async fn cloud_browser_extension_delete(
&self,
extension_id: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_extension_delete( &self, extension_id: &str, ) -> Result<Value, ScrapflyError>
Delete a browser extension by ID.
Sourcepub async fn cloud_browser_playback(
&self,
run_id: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_playback( &self, run_id: &str, ) -> Result<Value, ScrapflyError>
Get debug recording playback metadata for a run.
Sourcepub async fn cloud_browser_session_stop(
&self,
session_id: &str,
) -> Result<(), ScrapflyError>
pub async fn cloud_browser_session_stop( &self, session_id: &str, ) -> Result<(), ScrapflyError>
Terminate a Cloud Browser session.
Sourcepub async fn cloud_browser_sessions(&self) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_sessions(&self) -> Result<Value, ScrapflyError>
List all running Cloud Browser sessions.
Sourcepub async fn cloud_browser_video(
&self,
run_id: &str,
) -> Result<Vec<u8>, ScrapflyError>
pub async fn cloud_browser_video( &self, run_id: &str, ) -> Result<Vec<u8>, ScrapflyError>
Download a debug session recording video (raw bytes).
Source§impl Client
impl Client
Sourcepub async fn create_scrape_schedule(
&self,
scrape_config: HashMap<String, Value>,
request: &CreateScheduleRequest,
) -> Result<Schedule, ScrapflyError>
pub async fn create_scrape_schedule( &self, scrape_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>
Create a Web Scraping API schedule.
Sourcepub async fn create_screenshot_schedule(
&self,
screenshot_config: HashMap<String, Value>,
request: &CreateScheduleRequest,
) -> Result<Schedule, ScrapflyError>
pub async fn create_screenshot_schedule( &self, screenshot_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>
Create a Screenshot API schedule.
Sourcepub async fn create_crawler_schedule(
&self,
crawler_config: HashMap<String, Value>,
request: &CreateScheduleRequest,
) -> Result<Schedule, ScrapflyError>
pub async fn create_crawler_schedule( &self, crawler_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>
Create a Crawler API schedule.
Sourcepub async fn get_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
pub async fn get_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
Return a schedule by id (works across all kinds).
Sourcepub async fn list_schedules(
&self,
opts: Option<&ListSchedulesOptions>,
) -> Result<Vec<Schedule>, ScrapflyError>
pub async fn list_schedules( &self, opts: Option<&ListSchedulesOptions>, ) -> Result<Vec<Schedule>, ScrapflyError>
List every schedule on the account, optionally filtered by kind/status.
Sourcepub async fn list_scrape_schedules(
&self,
status: Option<&str>,
) -> Result<Vec<Schedule>, ScrapflyError>
pub async fn list_scrape_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>
List scrape schedules, optionally filtered by status.
Sourcepub async fn list_screenshot_schedules(
&self,
status: Option<&str>,
) -> Result<Vec<Schedule>, ScrapflyError>
pub async fn list_screenshot_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>
List screenshot schedules, optionally filtered by status.
Sourcepub async fn list_crawler_schedules(
&self,
status: Option<&str>,
) -> Result<Vec<Schedule>, ScrapflyError>
pub async fn list_crawler_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>
List crawler schedules, optionally filtered by status.
Sourcepub async fn update_schedule(
&self,
id: &str,
request: &UpdateScheduleRequest,
) -> Result<Schedule, ScrapflyError>
pub async fn update_schedule( &self, id: &str, request: &UpdateScheduleRequest, ) -> Result<Schedule, ScrapflyError>
Patch an active schedule. Only fields set in request change.
Sourcepub async fn cancel_schedule(&self, id: &str) -> Result<(), ScrapflyError>
pub async fn cancel_schedule(&self, id: &str) -> Result<(), ScrapflyError>
Cancel a schedule. Cancellation is terminal (returns no body).
Sourcepub async fn pause_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
pub async fn pause_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
Pause an active schedule. Idempotent on already-paused schedules.
Sourcepub async fn resume_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
pub async fn resume_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
Resume a paused schedule. Idempotent on already-active schedules.
Sourcepub async fn execute_schedule(
&self,
id: &str,
) -> Result<Schedule, ScrapflyError>
pub async fn execute_schedule( &self, id: &str, ) -> Result<Schedule, ScrapflyError>
Fire a schedule immediately, regardless of next_scheduled_date.