kuchiki-rs / kuchiki

(朽木) HTML/XML tree manipulation library for Rust
MIT License
470 stars 54 forks source link

Error "type mismatch resolving" with from_file() method #24

Closed LeMoussel closed 1 year ago

LeMoussel commented 8 years ago

tried to use kuchiki like this

let html_file = Path::new("cocon1.html");
let document = kuchiki::parse_html().from_file(html_file);

But I got his error

src\main.rs:44:42: 44:51 error: type mismatch resolving `<html5ever::tendril::fmt::UTF8 as html5ever::tendril::fmt::SliceFormat>::Slice == [u8]`:
 expected str,
    found slice [E0271]
src\main.rs:44     let document = kuchiki::parse_html().from_file(html_file);
                                                        ^~~~~~~~~

Rem : Wiith htm5ever, It's OK with this code:

let dom = parse_document(RcDom::default(), Default::default())
                .from_utf8()
                .from_file(html_file)
                .unwrap();
LeMoussel commented 8 years ago

I found this solution :

    let html_file =  Path::new("cocon1.html").to_path_buf();
    let document = kuchiki::parse_html().from_utf8().from_file(&html_file).unwrap();
    println!("{}", document.to_string());
ghlecl commented 6 years ago

@LeMoussel Thank you so very much. I have been trying to find a "tutorial" to read and parse an HTML file in Rust for quite some time and those three lines (plus a few use and extern crate) did the job. So thankful.

SimonSapin commented 1 year ago

I will soon archive this repository and make it read-only, so this issue will not be addressed: https://github.com/kuchiki-rs/kuchiki#archived