Skip to content

About

Determine if a page may be crawled from robots.txt, robots meta tags and robot headers

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Parse robots.txt, robots meta and headers

Latest version on crates.io Tests License Total downloads

Determine if a page may be crawled from robots.txt, robots meta tags and robot headers.

A Rust port of spatie/robots-txt.

Support us

Support Spatie's open source work

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

Requires Rust 1.89 or newer. You can install the package with Cargo:

cargo add spatie-robots-txt

Usage

use spatie_robots_txt::RobotsTxt;

let robots_txt = RobotsTxt::new("
  User-agent: *
  Disallow: /admin
  Crawl-delay: 1.5
");

robots_txt.allows_for("/admin", "google"); // false
robots_txt.why_disallows("/admin", "google"); // Some(reasons), user_agent is "*"
robots_txt.crawl_delay(); // Some("1.5")
# assert!(!robots_txt.allows_for("/admin", "google"));
# assert_eq!(robots_txt.why_disallows("/admin", "google").unwrap()[0].user_agent, "*");
# assert_eq!(robots_txt.crawl_delay(), Some("1.5"));

To check a page, including its meta tags and headers:

# fn main() -> Result<(), spatie_robots_txt::Error> {
use spatie_robots_txt::Robots;

let robots = Robots::create();

robots.may_index("https://www.spatie.be/nl/admin")?;
robots.may_follow_on("https://www.spatie.be/nl/admin")?;
# Ok(())
# }

You can also specify a user agent:

# use spatie_robots_txt::Robots;
let robots = Robots::create().user_agent("UserAgent007");
# let _ = robots;

By default, Robots will look for a robots.txt file on https://host.com/robots.txt. Another location can be specified with with_txt_from. Use with_txt to supply a parsed RobotsTxt.

The HTTP convenience methods are blocking. The parsers work without network access and can inspect content fetched by any HTTP client. See the usage guide. An unreadable robots.txt allows crawling by default; use try_read_from to handle loading errors explicitly.

Testing

cargo test --locked --all-targets --all-features
cargo test --locked --doc --all-features

See all quality checks. The README and Markdown guides are tested by rustdoc, including setup on hidden # lines.

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md and the Rust API Guidelines.

Using an AI coding agent? Load Apollo's rust-best-practices skill when writing or reviewing code in this package.

Security Vulnerabilities

Report vulnerabilities privately using the instructions in SECURITY.md.

Credits

License

The MIT License (MIT). See LICENSE.md.

About

Determine if a page may be crawled from robots.txt, robots meta tags and robot headers

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages