-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathrss.rs
36 lines (30 loc) · 931 Bytes
/
rss.rs
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
//! `cargo run --example rss`
extern crate spider;
use spider::tokio;
use spider::website::Website;
use tokio::io::AsyncWriteExt;
#[tokio::main]
async fn main() {
let mut website: Website = Website::new("https://a11ywatch.com/rss")
.with_limit(5)
.build()
.unwrap();
let mut rx2: tokio::sync::broadcast::Receiver<spider::page::Page> =
website.subscribe(16).unwrap();
tokio::spawn(async move {
let mut stdout = tokio::io::stdout();
while let Ok(res) = rx2.recv().await {
let _ = stdout
.write_all(format!("- {}\n", res.get_url()).as_bytes())
.await;
}
});
let start = std::time::Instant::now();
website.crawl().await;
let duration = start.elapsed();
println!(
"Time elapsed in website.crawl() is: {:?} for total pages: {:?}",
duration,
website.get_links().len()
)
}