Respecting robots.txt | rust-crawler | Spatie       

 SPATIE  

rust-crawler
============

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Rust-crawler](https://spatie.be/docs/rust-crawler/v1)  Configuring-the-crawler  Respecting robots.txt

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/rust-crawler/v1) 

  Respecting robots.txt    
- [ Introduction ](https://spatie.be/docs/rust-crawler/v1/introduction)
- [ Installation &amp; setup ](https://spatie.be/docs/rust-crawler/v1/installation-setup)
- [ Support us ](https://spatie.be/docs/rust-crawler/v1/support-us)
- [ Questions and issues ](https://spatie.be/docs/rust-crawler/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/rust-crawler/v1/changelog)
- [ About us ](https://spatie.be/docs/rust-crawler/v1/about-us)

Basic usage
-----------

- [ Your first crawl ](https://spatie.be/docs/rust-crawler/v1/basic-usage/starting-your-first-crawl)
- [ Crawl responses ](https://spatie.be/docs/rust-crawler/v1/basic-usage/handling-crawl-responses)
- [ Using observers ](https://spatie.be/docs/rust-crawler/v1/basic-usage/using-observers)
- [ Collecting URLs ](https://spatie.be/docs/rust-crawler/v1/basic-usage/collecting-urls)
- [ Filtering URLs ](https://spatie.be/docs/rust-crawler/v1/basic-usage/filtering-urls)
- [ Testing ](https://spatie.be/docs/rust-crawler/v1/basic-usage/testing)
- [ Tracking progress ](https://spatie.be/docs/rust-crawler/v1/basic-usage/tracking-progress)

Configuring the crawler
-----------------------

- [ Concurrency &amp; throttling ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/crawl-behavior)
- [ Limits ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/setting-crawl-limits)
- [ Extracting resources ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/extracting-resources)
- [ Configuring requests ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/configuring-requests)
- [ Response filtering ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/handling-responses)
- [ Respecting robots.txt ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/respecting-robots-txt)

Advanced usage
--------------

- [ JavaScript rendering ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/rendering-javascript)
- [ Custom link extraction ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/extracting-custom-links)
- [ Custom request handlers ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/custom-request-handlers)
- [ Crawling across requests ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/crawling-across-requests)
- [ Custom crawl queue ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/using-a-custom-crawl-queue)
- [ Graceful shutdown ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/graceful-shutdown)

 Respecting robots.txt
=====================

###  On this page 

1. [ Enabling and disabling robots rules ](#content-enabling-and-disabling-robots-rules)
2. [ Fetching robots.txt ](#content-fetching-robotstxt)
3. [ Accepting nofollow links ](#content-accepting-nofollow-links)
4. [ Document indexing and following ](#content-document-indexing-and-following)
5. [ Custom user agent ](#content-custom-user-agent)

The crawler respects robots.txt, HTML meta robots and `X-Robots-Tag` response headers by default. Robots.txt matching uses the `texting_robots` Rust dependency and the configured user agent, `SpatieCrawler/0.1` by default.

Enabling and disabling robots rules
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Use the boolean `respect_robots` builder method. These methods consume the builder, so retain the returned value when changing it later.

```
use spatie_crawler::Crawler;

fn robots_disabled() -> spatie_crawler::Result {
    Crawler::builder("https://example.com")?
        .respect_robots(false)
        .build()
}

fn robots_reenabled() -> spatie_crawler::Result {
    let builder = Crawler::builder("https://example.com")?.respect_robots(false);
    builder.respect_robots(true).build()
}
```

Disabling robots enforcement disables robots.txt access decisions and document-level noindex/nofollow enforcement. It does not automatically enable link-level `rel="nofollow"` extraction, which has a separate option. `discover_sitemaps(true)` can still fetch robots.txt for Sitemap declarations even when enforcement is disabled.

Fetching robots.txt
---------------------------------------------------------------------------------------------------------------

Robots.txt is loaded separately and cached per scheduled origin for the execution. Its request uses the configured transport, headers, timeout and body-size cap, but not crawler request hooks or the page retry loop. Transport middleware does wrap it. Robots fetches do not emit page events or count toward page attempts. Path include/exclude filters do not prevent fetching the origin's robots file; robots redirects must stay within that origin.

A robots.txt response with status 401, 403 or 5xx, or a network/body-size/deadline error, denies access. Other HTTP 4xx responses impose no rules. Matching `Crawl-delay` can increase [per-origin pacing](crawl-behavior), up to the implementation's one-day clamp.

Robots access decisions and pacing apply to scheduled URLs, not intermediate HTTP redirect hops. A redirect target still has to pass the built-in transport's network and crawl-policy checks, but following a redirect does not first fetch that target origin's robots.txt or wait for its pacing lane. Do not treat robots support as enforcement on every network hop.

`always_crawl` and `always_crawl_glob` bypass robots.txt checks for matching URLs as well as normal host and include/exclude policy. They do not disable document-level noindex/nofollow enforcement, depth, timeout, body-size or network safeguards. Use these overrides only deliberately.

Accepting nofollow links
--------------------------------------------------------------------------------------------------------------------------------

The default `HtmlExtractor` excludes links with `rel="nofollow"`. Configure the extractor, not the crawler, to include them.

```
use spatie_crawler::{Crawler, HtmlExtractor};

fn include_nofollow_links() -> spatie_crawler::Result {
    let extractor = HtmlExtractor::default().follow_nofollow(true);
    Crawler::builder("https://example.com")?
        .extractor(extractor)
        .build()
}
```

Use `.follow_nofollow(false)` to restore rejection. This only affects link-level extraction. With robots enabled, a page's meta robots or `X-Robots-Tag` nofollow directive still prevents scheduling its discoveries, even when `follow_nofollow(true)` is set.

Document indexing and following
-----------------------------------------------------------------------------------------------------------------------------------------------------

Document flags appear as `page.document.may_index` and `page.document.may_follow` before enforcement. Meta robots and repeated `X-Robots-Tag` headers can set noindex/nofollow; `none` sets both.

With robots enabled, noindex produces a `Skipped` event with reason `"noindex"` instead of a `Page` event. The page was fetched and counts toward its page budget. Unless it also forbids following, it can still contribute links. Document-level nofollow prevents discovery scheduling; it does not make the page itself a failed request. A robots.txt refusal produces `Skipped` with reason `"robots.txt"` before a page fetch and does not consume a page attempt.

Custom user agent
-----------------------------------------------------------------------------------------------------------

Use `user_agent` to keep the HTTP header and robots matching identity consistent.

```
use spatie_crawler::Crawler;

fn named_robot() -> spatie_crawler::Result {
    Crawler::builder("https://example.com")?
        .user_agent("DocumentationBot/1.0")
        .build()
}
```

See [configuring requests](configuring-requests) for authentication, headers and transport configuration, and [extracting resources](extracting-resources) for the distinction between extraction and scheduling.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
