-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathchrome.rs
More file actions
52 lines (41 loc) · 1.27 KB
/
chrome.rs
File metadata and controls
52 lines (41 loc) · 1.27 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
44
45
46
47
48
49
50
51
52
//! cargo run --example chrome --features chrome
extern crate spider;
use spider::features::chrome_common::RequestInterceptConfiguration;
use spider::tokio;
use spider::website::Website;
use std::io::Result;
async fn crawl_website(url: &str) -> Result<()> {
let mut website: Website = Website::new(url)
.with_limit(10)
.with_chrome_intercept(RequestInterceptConfiguration::new(true))
.with_stealth(true)
.build()
.unwrap();
let mut rx2 = website.subscribe(16);
let handle = tokio::spawn(async move {
while let Ok(page) = rx2.recv().await {
println!("{:?}", page.get_url());
}
});
let start = crate::tokio::time::Instant::now();
website.crawl().await;
website.unsubscribe();
let _ = handle.await;
let duration = start.elapsed();
let links = website.get_all_links_visited().await;
println!(
"Time elapsed in website.crawl({url}) is: {:?} for total pages: {:?}",
duration,
links.len()
);
Ok(())
}
#[tokio::main]
async fn main() -> Result<()> {
let _ = tokio::join!(
crawl_website("https://choosealicense.com"),
crawl_website("https://jeffmendez.com"),
crawl_website("https://github.com/spider-rs"),
);
Ok(())
}