| 1 |
//! Pure rust version for comparing with python based calls |
| 2 |
|
| 3 |
use kuchiki; |
| 4 |
|
| 5 |
use std::env; |
| 6 |
use std::path::PathBuf; |
| 7 |
use std::time::Instant; |
| 8 |
use tendril::stream::TendrilSink; |
| 9 |
|
| 10 |
fn main() { |
| 11 |
let path = PathBuf::from( |
| 12 |
env::args() |
| 13 |
.nth(1) |
| 14 |
.expect("You need to pass the file name as first argument"), |
| 15 |
); |
| 16 |
|
| 17 |
let now = Instant::now(); |
| 18 |
let document = kuchiki::parse_html().from_utf8().from_file(&path).unwrap(); |
| 19 |
println!("{:?}", now.elapsed()); |
| 20 |
let now2 = Instant::now(); |
| 21 |
let links: Vec<String> = document |
| 22 |
.select("a[href]") |
| 23 |
.unwrap() |
| 24 |
.map(|css_match| css_match.text_contents()) |
| 25 |
.collect(); |
| 26 |
println!("{} {:?}", links.len(), now2.elapsed()); |
| 27 |
} |