#html-parser #query-parser #parser #html #query #dom

html_query_parser

Pure, simple and elegant HTML parser and query selector

5 unstable releases

0.3.1 Jan 1, 2022
0.3.0 Jan 1, 2022
0.2.1 Dec 27, 2021
0.2.0 Dec 27, 2021
0.1.0 Dec 23, 2021

#55 in #query-parser

24 downloads per month

MIT license

33KB
678 lines

Warning

This repository has been deprecated, please use the html-editor instead.

If you want to have the ownership of this crate name, please contact me at lomirus@qq.com so I can transfer it to you.

Crates.io

HTML Query Parser

Pure, simple and elegant HTML parser and query selector.

Examples

Parse HTML segment/document

let document = parse("<!doctype html><html><head></head><body></body></html>");
println!("{:#?}", document);

Output:

[
    Doctype,
    Element {
        name: "html",
        attrs: {},
        children: [
            Element {
                name: "head",
                attrs: {},
                children: [],
            },
            Element {
                name: "body",
                attrs: {},
                children: [],
            },
        ],
    },
]

Query an element by classname

// let html = r#"..."#
let nodes = parse(html);
let selector: Selector = Selector::from(".last");
let element: Element = nodes.query(&selector).unwrap();

Query all elements by tag

// let html = r#"..."#
let nodes = parse(html);
let selector: Selector = Selector::from("span");
let elements: Vec<Element> = nodes.query_all(&selector);

Edit the HTML

// let html = r#"..."#
let a: String = parse(html).trim().html();
let b: String = parse(html).insert_to(&selector, node).html();
let c: String = parse(html).remove_by(&selector).html();

You can find more examples in the documentation.

Changelog

See in CHANGELOG.md

No runtime deps