crawl

Crates.iocrawl
lib.rscrawl
version0.2.1
sourcesrc
created_at2024-01-05 04:14:23.005636
updated_at2024-01-10 08:27:29.624445
descriptionRust crawl
homepage
repositoryhttps://github.com/007gzs/crawl/
max_upload_size
id1089274
size89,973
(007gzs)

documentation

README

Crawl

Rust crawl

demo


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(())
}

Commit count: 0

cargo fmt