1 unstable release
0.1.0 | Jul 10, 2019 |
---|
#15 in #robots-txt
15KB
266 lines
A robots.txt parser and applicability checker for Rust
Usage
Add it to your Cargo.toml
:
[dependencies]
robots-parser = "0.10"
Examples
Parse and check from URL
use robots::RobotsParser;
use url::Url;
fn main() {
let parsed = RobotsParser::parse_url(Url::new("https://www.google.com/robots.txt"))?;
assert!(parsed.can_fetch("*", "https://www.google.com/search/about"));
}
Parse and check from File
use robots::RobotsParser;
fn main() {
let parsed = RobotsParser::parse_path("~/test-robots.txt"))?;
assert!(parsed.can_fetch("*", "http://test.com/can_fetch"));
}
Parse and check from &str
use robots::RobotsParser;
fn main() {
let parsed = RobotsParser::parse_path("Disallow: /test"))?;
assert!(!parsed.can_fetch("*", "http://test.com/test"));
}
License
This work is released under Apache and MIT license. A copy of the licenses are provided in the LICENSE-APACHE and LICENSE-MIT files.
Dependencies
~2.2–6MB
~127K SLoC