Crates.io | crawl |
lib.rs | crawl |
version | 0.2.1 |
source | src |
created_at | 2024-01-05 04:14:23.005636 |
updated_at | 2024-01-10 08:27:29.624445 |
description | Rust crawl |
homepage | |
repository | https://github.com/007gzs/crawl/ |
max_upload_size | |
id | 1089274 |
size | 89,973 |
Rust crawl
fn main() -> anyhow::Result<()> {
let download = Arc::new(Downloader::new(
String::from(r"data/book1"),
String::from("https://doc.rust-lang.org/book/")
));
let url = String::from("https://doc.rust-lang.org/book/index.html");
let manager = Arc::new(Mutex::new(Manager{datas:Vec::new(), added_urls:HashSet::from([url.clone()])}));
download.start_url(url, false, Arc::new(Flag::Page))?;
for _ in 0..16{
let res_arg = get_res_thread_arg(&download);
let r = Arc::clone(&manager);
thread::spawn(move || res_run(res_arg, r));
}
start_crawl(&download, 16);
download.wait_finish();
{
let m = manager.lock().unwrap();
println!("finish {}", m.datas.len());
for item in m.datas.iter(){
println!("{} {}", item.url, item.title);
}
}
Ok(())
}