Thanks to visit codestin.com
Credit goes to lib.rs

3 releases

new 0.0.7 Dec 26, 2025
0.0.6 Dec 26, 2025
0.0.5 Dec 22, 2025

#1812 in Web programming

MIT license

55KB
1.5K SLoC

domparser

A super fast html parser and manipulator written in rust.

Installation

Add this to your Cargo.toml:

[dependencies]
domparser = "0.0.5"

Usage

use domparser::parse;

fn main() {
    let html = r#"<div id="foo" class="bar">hello <span>world</span></div>"#;
    let root = parse(html.to_string());

    let div = root.select("div".to_string()).unwrap();
    println!("{}", div.get_attribute("id".to_string()).unwrap()); // "foo"
    println!("{}", div.text()); // "hello world"
    
    div.set_attribute("title".to_string(), "my-title".to_string());
    println!("{}", div.outer_html()); 
    // <div id="foo" class="bar" title="my-title">hello <span>world</span></div>
}

Features

  • Parse HTML string to DOM
  • Select nodes with CSS selectors
  • Manipulate attributes and text
  • Serialize DOM back to HTML

Dependencies

~2.5MB
~47K SLoC