Skip to main content

Client

Struct Client 

Source
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

Source

pub fn builder() -> ClientBuilder

Start a new ClientBuilder.

Source

pub fn api_key(&self) -> &str

Return the configured API key.

Source

pub fn host(&self) -> &str

Return the configured API host.

Source

pub fn cloud_browser_host(&self) -> &str

Return the configured Cloud Browser host.

Source

pub async fn verify_api_key(&self) -> Result<VerifyApiKeyResult, ScrapflyError>

Verify the API key by hitting /account.

Source

pub async fn account(&self) -> Result<AccountData, ScrapflyError>

Fetch account info.

Source

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.

Source

pub async fn get_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch aggregate monitoring metrics for the Web Scraping API.

Source

pub async fn get_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch per-target monitoring metrics for the Web Scraping API.

Source

pub async fn get_screenshot_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch aggregate monitoring metrics for the Screenshot API.

Source

pub async fn get_screenshot_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch per-target monitoring metrics for the Screenshot API.

Source

pub async fn get_extraction_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch aggregate monitoring metrics for the Extraction API.

Source

pub async fn get_extraction_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch per-target monitoring metrics for the Extraction API.

Source

pub async fn get_crawler_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch aggregate monitoring metrics for the Crawler API.

Source

pub async fn get_crawler_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch per-target monitoring metrics for the Crawler API.

Source

pub async fn get_browser_monitoring_metrics( &self, opts: &CloudBrowserMonitoringOptions, ) -> Result<Value, ScrapflyError>

Fetch aggregate monitoring metrics for the Cloud Browser API.

Source

pub async fn get_browser_monitoring_timeseries( &self, opts: &CloudBrowserMonitoringOptions, ) -> Result<Value, ScrapflyError>

Fetch monitoring time-series for the Cloud Browser API.

Source

pub async fn scrape( &self, config: &ScrapeConfig, ) -> Result<ScrapeResult, ScrapflyError>

Scrape a URL.

Source

pub fn concurrent_scrape<'a, I>( &'a self, configs: I, concurrency_limit: usize, ) -> impl Stream<Item = Result<ScrapeResult, ScrapflyError>> + 'a
where I: IntoIterator<Item = ScrapeConfig> + 'a, <I as IntoIterator>::IntoIter: 'a,

Concurrent-scrape stream. Emits results in completion order.

Source

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.

Source

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.).

Source

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.

Source

pub async fn screenshot( &self, config: &ScreenshotConfig, ) -> Result<ScreenshotResult, ScrapflyError>

Screenshot a URL.

Source

pub async fn extract( &self, config: &ExtractionConfig, ) -> Result<ExtractionResult, ScrapflyError>

Run AI extraction on a document.

Source

pub async fn start_crawl( &self, config: &CrawlerConfig, ) -> Result<CrawlerStartResponse, ScrapflyError>

Schedule a new crawler job.

Source

pub async fn crawl_status( &self, uuid: &str, ) -> Result<CrawlerStatus, ScrapflyError>

Fetch crawler status.

Source

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).

Source

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.

Source

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.

Source

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).

Source

pub async fn crawl_cancel(&self, uuid: &str) -> Result<(), ScrapflyError>

Cancel a crawler job.

Source

pub async fn crawl_artifact( &self, uuid: &str, artifact_type: CrawlerArtifactType, ) -> Result<CrawlerArtifact, ScrapflyError>

Download a crawler artifact (WARC or HAR).

Source§

impl Client

Source

pub fn cloud_browser_url(&self, config: &BrowserConfig) -> String

Build the WebSocket URL for a new Cloud Browser session.

Source

pub async fn cloud_browser_unblock( &self, config: &UnblockConfig, ) -> Result<UnblockResult, ScrapflyError>

Call POST /unblock to bypass anti-bot protection.

Source

pub async fn cloud_browser_extension_list(&self) -> Result<Value, ScrapflyError>

List browser extensions for the account.

Source

pub async fn cloud_browser_extension_get( &self, extension_id: &str, ) -> Result<Value, ScrapflyError>

Get details of a specific browser extension.

Source

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).

Source

pub async fn cloud_browser_extension_delete( &self, extension_id: &str, ) -> Result<Value, ScrapflyError>

Delete a browser extension by ID.

Source

pub async fn cloud_browser_playback( &self, run_id: &str, ) -> Result<Value, ScrapflyError>

Get debug recording playback metadata for a run.

Source

pub async fn cloud_browser_session_stop( &self, session_id: &str, ) -> Result<(), ScrapflyError>

Terminate a Cloud Browser session.

Source

pub async fn cloud_browser_sessions(&self) -> Result<Value, ScrapflyError>

List all running Cloud Browser sessions.

Source

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

Source

pub async fn create_scrape_schedule( &self, scrape_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>

Create a Web Scraping API schedule.

Source

pub async fn create_screenshot_schedule( &self, screenshot_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>

Create a Screenshot API schedule.

Source

pub async fn create_crawler_schedule( &self, crawler_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>

Create a Crawler API schedule.

Source

pub async fn get_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>

Return a schedule by id (works across all kinds).

Source

pub async fn list_schedules( &self, opts: Option<&ListSchedulesOptions>, ) -> Result<Vec<Schedule>, ScrapflyError>

List every schedule on the account, optionally filtered by kind/status.

Source

pub async fn list_scrape_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>

List scrape schedules, optionally filtered by status.

Source

pub async fn list_screenshot_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>

List screenshot schedules, optionally filtered by status.

Source

pub async fn list_crawler_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>

List crawler schedules, optionally filtered by status.

Source

pub async fn update_schedule( &self, id: &str, request: &UpdateScheduleRequest, ) -> Result<Schedule, ScrapflyError>

Patch an active schedule. Only fields set in request change.

Source

pub async fn cancel_schedule(&self, id: &str) -> Result<(), ScrapflyError>

Cancel a schedule. Cancellation is terminal (returns no body).

Source

pub async fn pause_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>

Pause an active schedule. Idempotent on already-paused schedules.

Source

pub async fn resume_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>

Resume a paused schedule. Idempotent on already-active schedules.

Source

pub async fn execute_schedule( &self, id: &str, ) -> Result<Schedule, ScrapflyError>

Fire a schedule immediately, regardless of next_scheduled_date.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T