-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathconfiguration.rs
More file actions
43 lines (36 loc) · 1.09 KB
/
configuration.rs
File metadata and controls
43 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! `cargo run --example configuration`
extern crate spider;
use spider::tokio;
use spider::website::Website;
use std::io::Error;
use std::time::Instant;
#[tokio::main]
async fn main() -> Result<(), Error> {
let mut website = Website::new("https://choosealicense.com")
.with_user_agent(Some("SpiderBot"))
.with_blacklist_url(Some(Vec::from([
"https://choosealicense.com/non-software".into()
])))
.with_subdomains(true)
.with_concurrency_limit(None)
.with_tld(true)
.with_respect_robots_txt(true)
.with_external_domains(Some(
Vec::from(["http://docs.rs/"].map(|d| d.to_string())).into_iter(),
))
.build()
.unwrap();
let start = Instant::now();
website.crawl().await;
let duration = start.elapsed();
let links = website.get_all_links_visited().await;
for link in links.iter() {
println!("- {:?}", link.as_ref());
}
println!(
"Time elapsed in website.crawl() is: {:?} for total pages: {:?}",
duration,
links.len()
);
Ok(())
}