9 releases
0.3.5 | Apr 4, 2024 |
---|---|
0.3.4 | Feb 17, 2024 |
0.3.2 | Jan 19, 2024 |
0.3.0 | Dec 31, 2023 |
0.1.11 | Dec 22, 2023 |
#2018 in Web programming
165 downloads per month
Used in dom_finder
185KB
2K
SLoC
DOM_QUERY
A crate for manipulating HTML with CSS selectors.
DOM_QUERY is based on HTML crate html5ever and the CSS selector crate selectors. You can use the jQuery-like syntax to query and manipulate an HTML document quickly. Not only can query, but also can modify.
It is a fork of nipper, with some updates. Also this fork supports :has
, :has-text
, :contains
pseudo-classes, and some others.
Example
Extract the hacker news.
use dom_query::Document;
fn main() {
let html = include_str!("../test-pages/hacker_news.html");
let document = Document::from(html);
document.select("tr.athing:has(a[href][id])").iter().for_each(|athing| {
let title = athing.select(".title a");
let href = athing.select(".storylink");
println!("{}", title.text());
println!("{}", href.attr("href").unwrap());
});
}
Readability.
Related projects
Features
hashbrown
-- optional, standard hashmaps and hashsets will be replacedhashbrown
hashmaps and hashsets;
Changelog
License
Licensed under MIT (LICENSE or http://opensource.org/licenses/MIT)
Contribution
Any contribution intentionally submitted for inclusion in the work by you, shall be licensed with MIT license, without any additional terms or conditions.
Dependencies
~2.6–8.5MB
~72K SLoC