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 agentdecide what is crawled; disallowed requests are skipped, andCrawl-delayslows the host down. - A
4xxother than429, or too many redirects, allows everything. - A
5xx, a429or 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.
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
impl Robots
Sourcepub fn new(user_agent: impl Into<Arc<str>>) -> Self
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.
Sourcepub fn with_backend<B: Backend>(self, backend: B) -> Self
pub fn with_backend<B: Backend>(self, backend: B) -> Self
Fetches robots.txt with backend instead of the crawl’s.
Sourcepub const fn with_max_age(self, age: Duration) -> Self
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.
Sourcepub const fn with_unreachable_retries(self, retries: u32) -> Self
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.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Robots
impl !UnwindSafe for Robots
impl Freeze for Robots
impl Send for Robots
impl Sync for Robots
impl Unpin for Robots
impl UnsafeUnpin for Robots
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more