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. [ Ignoring robots rules ](#content-ignoring-robots-rules)
2. [ Accepting nofollow links ](#content-accepting-nofollow-links)
3. [ Custom user agent ](#content-custom-user-agent)
4. [ Fetching robots.txt ](#content-fetching-robotstxt)
5. [ Document indexing and following ](#content-document-indexing-and-following)

By default, the crawler will respect robots data from robots.txt files, meta tags, and response headers. Robots.txt matching uses the `texting_robots` crate and the configured user agent.

Ignoring robots rules
-----------------------------------------------------------------------------------------------------------------------

You can disable robots enforcement using `respect_robots(false)`.

```
use spatie_crawler::Crawler;

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

You can re-enable robots checking after disabling it using `respect_robots(true)`. Builder methods consume the builder, so retain the returned value when changing it later.

```
use spatie_crawler::Crawler;

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.

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

By default, the crawler will reject all links containing `rel="nofollow"`. You can disable this check using `follow_nofollow(true)` on the extractor.

```
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()
}
```

You can re-enable nofollow rejection using `follow_nofollow(false)`. 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.

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

The [user agent](configuring-requests#user-agent) is also used when checking robots.txt rules. When you set a custom user agent, rules specific to that agent will be respected. For example, if robots.txt contains:

```
User-agent: my-agent
Disallow: /
```

The crawler using `my-agent` will not crawl any pages on the site.

```
use spatie_crawler::Crawler;

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

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.

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#request-delay), up to one day.

Robots checks do not cover intermediate page redirect hops. See [network safety](configuring-requests#network-safety) for redirect checks and credential handling.

`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.

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.

See [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)
