Spider

Struct Spider 

Source
pub struct Spider {
    pub api_key: String,
    pub client: Client,
}
Expand description

Represents a Spider with API key and HTTP client.

Fields§

§api_key: String

The Spider API key.

§client: Client

The Spider Client to re-use.

Implementations§

Source§

impl Spider

Source

pub fn new(api_key: Option<String>) -> Result<Self, &'static str>

Creates a new instance of Spider.

§Arguments
  • api_key - An optional API key. Defaults to using the ‘SPIDER_API_KEY’ env variable.
§Returns

A new instance of Spider or an error string if no API key is provided.

Source

pub fn new_with_client( api_key: Option<String>, client: Client, ) -> Result<Self, &'static str>

Creates a new instance of Spider.

§Arguments
  • api_key - An optional API key. Defaults to using the ‘SPIDER_API_KEY’ env variable.
  • client - A custom client to pass in.
§Returns

A new instance of Spider or an error string if no API key is provided.

Source

pub async fn api_post( &self, endpoint: &str, data: impl Serialize + Debug + Clone + Send + Sync, content_type: &str, ) -> Result<Response, Error>

Sends a POST request to the API.

§Arguments
  • endpoint - The API endpoint.
  • data - The request data as a HashMap.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API.

Source

pub async fn api_get<T: Serialize>( &self, endpoint: &str, query_params: Option<&T>, ) -> Result<Value, Error>

Sends a GET request to the API.

§Arguments
  • endpoint - The API endpoint.
§Returns

The response from the API as a JSON value.

Source

pub async fn api_delete( &self, endpoint: &str, params: Option<HashMap<String, Value>>, ) -> Result<Response, Error>

Sends a DELETE request to the API.

§Arguments
  • endpoint - The API endpoint.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API.

Source

pub async fn scrape_url( &self, url: &str, params: Option<RequestParams>, content_type: &str, ) -> Result<Value, Error>

Scrapes a URL.

§Arguments
  • url - The URL to scrape.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn multi_scrape_url( &self, params: Option<Vec<RequestParams>>, content_type: &str, ) -> Result<Value, Error>

Scrapes multi URLs.

§Arguments
  • url - The URL to scrape.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn crawl_url( &self, url: &str, params: Option<RequestParams>, stream: bool, content_type: &str, callback: Option<impl Fn(Value) + Send>, ) -> Result<Value, Error>

Crawls a URL.

§Arguments
  • url - The URL to crawl.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
  • callback - Optional callback function to handle each streamed chunk.
§Returns

The response from the API as a JSON value.

Source

pub async fn multi_crawl_url( &self, params: Option<Vec<RequestParams>>, stream: bool, content_type: &str, callback: Option<impl Fn(Value) + Send>, ) -> Result<Value, Error>

Crawls multiple URLs.

§Arguments
  • url - The URL to crawl.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
  • callback - Optional callback function to handle each streamed chunk.
§Returns

The response from the API as a JSON value.

Fetches links from a URL.

§Arguments
  • url - The URL to fetch links from.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Fetches links from a URLs.

§Arguments
  • url - The URL to fetch links from.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn screenshot( &self, url: &str, params: Option<RequestParams>, _stream: bool, content_type: &str, ) -> Result<Value, Error>

Takes a screenshot of a URL.

§Arguments
  • url - The URL to take a screenshot of.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn multi_screenshot( &self, params: Option<Vec<RequestParams>>, _stream: bool, content_type: &str, ) -> Result<Value, Error>

Takes a screenshot of multiple URLs.

§Arguments
  • url - The URL to take a screenshot of.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn search( &self, q: &str, params: Option<SearchRequestParams>, _stream: bool, content_type: &str, ) -> Result<Value, Error>

Searches for a query.

§Arguments
  • q - The query to search for.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Searches for multiple querys.

§Arguments
  • q - The query to search for.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn unblock_url( &self, url: &str, params: Option<RequestParams>, content_type: &str, ) -> Result<Value, Error>

Unblock a URL.

§Arguments
  • url - The URL to scrape.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn multi_unblock_url( &self, params: Option<Vec<RequestParams>>, content_type: &str, ) -> Result<Value, Error>

Unblock multi URLs.

§Arguments
  • url - The URL to scrape.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn transform( &self, data: Vec<HashMap<&str, &str>>, params: Option<TransformParams>, _stream: bool, content_type: &str, ) -> Result<Value, Error>

Transforms data.

§Arguments
  • data - The data to transform.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn get_credits(&self) -> Result<Value, Error>

Get the account credits left.

Source

pub async fn data_post( &self, table: &str, data: Option<RequestParams>, ) -> Result<Value, Error>

Send a request for a data record.

Source

pub async fn data_get( &self, table: &str, params: Option<RequestParams>, ) -> Result<Value, Error>

Get a table record.

Trait Implementations§

Source§

impl Debug for Spider

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Spider

Source§

fn default() -> Spider

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Spider

§

impl !RefUnwindSafe for Spider

§

impl Send for Spider

§

impl Sync for Spider

§

impl Unpin for Spider

§

impl !UnwindSafe for Spider

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> 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, 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