Skip to main content

CrawlerEngine

Struct CrawlerEngine 

Source
pub struct CrawlerEngine<S: Spider> { /* private fields */ }
Expand description

Runs a Spider to completion (or until paused).

The engine dequeues requests by priority and processes them concurrently up to the spider’s global and per-domain limits. Each request goes through robots.txt checks (when enabled), the allowed-domains filter, the dev-mode cache, politeness delays (static or AutoThrottle), the session fetch, blocked-response detection with retries, and finally the spider’s parse callback — whose items are piped through on_scraped_item and whose follow-up requests are enqueued (deduplicated).

Construct with CrawlerEngine::new, run with CrawlerEngine::crawl, and optionally pause a running crawl with CrawlerEngine::request_pause — a paused crawl writes a checkpoint that the next run restores automatically.

Implementations§

Source§

impl<S: Spider> CrawlerEngine<S>

Source

pub fn new( spider: Arc<S>, session_manager: SessionManager, crawl_dir: Option<&str>, ) -> Result<Self, FetcherError>

Build an engine for spider.

session_manager provides the HTTP sessions (its "default" session is created here if missing — the reason this can fail with FetcherError). crawl_dir overrides where the dev cache and checkpoints live; None uses .scrapling/<spider name>/.

Source

pub fn request_pause(&self)

Ask a running crawl to pause. The crawl loop stops dispatching, waits for in-flight requests to finish, writes a checkpoint (pending requests plus the dedup set), and returns a CrawlResult with paused == true. The next CrawlerEngine::crawl with the same spider/crawl dir resumes from that checkpoint.

Source

pub async fn crawl(self) -> CrawlResult

Run the crawl to completion (or until paused) and return the scraped items and stats.

Restores a checkpoint if one exists (skipping the start requests), pre-fetches robots.txt for the seed origins when the spider obeys robots.txt, then drives the crawl loop until the queue is empty and no tasks are in flight. On normal completion the checkpoint is cleaned up; on pause it is written (see CrawlerEngine::request_pause).

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for CrawlerEngine<S>

§

impl<S> !UnwindSafe for CrawlerEngine<S>

§

impl<S> Freeze for CrawlerEngine<S>

§

impl<S> Send for CrawlerEngine<S>

§

impl<S> Sync for CrawlerEngine<S>

§

impl<S> Unpin for CrawlerEngine<S>

§

impl<S> UnsafeUnpin for CrawlerEngine<S>

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: Sized + 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: Sized + 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> Same for T

Source§

type Output = T

Should always be Self
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