-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathwarc_chrome.rs
More file actions
49 lines (38 loc) · 1.46 KB
/
warc_chrome.rs
File metadata and controls
49 lines (38 loc) · 1.46 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
//! WARC output with Chrome rendering — archives JavaScript-rendered pages.
//!
//! cargo run --example warc_chrome --features "spider/sync,spider/warc,spider/chrome"
//!
//! The WARC writer hooks into the same broadcast channel as HTTP crawls, so
//! Chrome-rendered pages are archived identically. The response records contain
//! the fully rendered HTML (post-JS execution).
extern crate spider;
use spider::tokio;
use spider::utils::warc::WarcConfig;
use spider::website::Website;
use std::time::Instant;
#[tokio::main]
async fn main() {
let url = std::env::args()
.nth(1)
.unwrap_or_else(|| "https://choosealicense.com".to_string());
let output_path = std::env::args()
.nth(2)
.unwrap_or_else(|| "output_chrome.warc".to_string());
let mut website: Website = Website::new(&url);
website.configuration.with_warc(WarcConfig {
path: output_path.clone(),
write_warcinfo: true,
..Default::default()
});
website.configuration.respect_robots_txt = true;
// Limit pages for the example.
website.configuration.with_limit(10);
let start = Instant::now();
website.crawl().await;
let duration = start.elapsed();
let links = website.get_all_links_visited().await;
let warc_records = website.warc_record_count();
println!("Crawled {} pages (Chrome) in {:?}", links.len(), duration);
println!("WARC records written: {warc_records}");
println!("Output: {output_path}");
}