rquery icon indicating copy to clipboard operation
rquery copied to clipboard

Query by class selector

Open horvayev opened this issue 5 years ago • 0 comments

How do I query by css class selector? Code below returns error;


use rquery::*;

#[allow(unused_variables)]
fn main() {
    let html = r#"
    <!DOCTYPE html>
        <html>
            <body>

                <h1 class="foo">My First Heading</h1>
                <p>My first paragraph.</p>

            </body>
    </html>
    "#;

    let doc = Document::new_from_xml_string(html);

    let doc= match doc {
        Ok(x) => {
            let title = match x.select(".foo") {
                Ok(t) => {
                    println!("{}", t.text());
                },
                Err(e) => {
                    println!("{}", format!("css err {:?}", e));
                }
            };
        },
        Err(e) => {
            println!("error");
        }
    };
}

horvayev avatar Oct 29 '20 20:10 horvayev