Skip to main content

Robots

Struct Robots 

Source
pub struct Robots { /* private fields */ }
Available on crate feature robots only.
Expand description

How a crawl fetches and obeys robots.txt, see Crawler::with_robots.

robots.txt is fetched once per origin (scheme, host and port) before its first request, and handled as RFC 9309 describes:

  • Its rules for user agent decide what is crawled; disallowed requests are skipped, and Crawl-delay slows the host down.
  • A 4xx other than 429, or too many redirects, allows everything.
  • A 5xx, a 429 or a network failure disallows everything while robots.txt is retried with backoff. Once the retries are spent, the origin’s requests are skipped.
  • Rules older than the maximum age are fetched again; until then, and if fetching fails, the old rules apply.

robots.txt is fetched with the crawl’s backend unless with_backend sets another, e.g. an HTTP client for a browser crawl. with_sitemaps also queues the sitemaps it lists.

use std::time::Duration;

use spire_core::backend::Noop;
use spire_core::crawler::Robots;

let robots = Robots::new("MyBot")
    .with_backend(Noop)
    .with_max_age(Duration::from_secs(3600));

Implementations§

Source§

impl Robots

Source

pub fn new(user_agent: impl Into<Arc<str>>) -> Self

Obeys robots.txt for user_agent, fetching it with the crawl’s backend, keeping it for 24 hours and retrying an unreachable one 3 times.

Source

pub fn with_backend<B: Backend>(self, backend: B) -> Self

Fetches robots.txt with backend instead of the crawl’s.

Source

pub const fn with_max_age(self, age: Duration) -> Self

Fetches robots.txt again once its rules are older than age. RFC 9309 asks for at most 24 hours.

Source

pub const fn with_unreachable_retries(self, retries: u32) -> Self

Retries an unreachable robots.txt retries times, 30 seconds apart and doubling, before skipping the origin’s requests.

Source

pub fn with_sitemaps(self, tag: impl Into<Tag>) -> Self

Queues the sitemaps an origin’s robots.txt lists in Sitemap: lines, tagged tag, the first time it is fetched.

They go through the frontier like any other seed, so its scope, deduplication and depth limits apply. Route the tag to a handler that parses them, e.g. FollowSitemap in spire.

Trait Implementations§

Source§

impl Clone for Robots

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Robots

Source§

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

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

impl From<&str> for Robots

Source§

fn from(user_agent: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Robots

Source§

fn from(user_agent: String) -> Self

Converts to this type from the input type.

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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<W> WorkerExt for W

Source§

fn layer<C, M>(self, middleware: M) -> Layered<M, C>
where C: Send + 'static, Self: Worker<C>, M: Middleware<C>,

Wraps this worker in middleware, which runs before it, and before any middleware added earlier.