Manipulation HTML with CSS Selectors.
Nipper 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.
```rust use nipper::Document;
let html = includestr!("../test-pages/hackernews.html"); let document = Document::from(html);
document.select("tr.athing").iter().for_each(|athing| { let title = athing.select(".title a"); let source = title.select(".sitestr"); // The next sibling. let meta = athing.next(); let score = meta.select("span.score"); let hnuser = meta.select("a.hnuser"); let age = meta.select("span.age"); // The last matched element. let comment = meta.select("a").last();
println!("Title: {}", title.text());
if source.exists() {
println!("> from: {}", source.text());
}
if score.exists() {
println!("> {}", score.text());
}
if hnuser.exists() {
println!("> by {}", hnuser.text());
}
println!("> {}", age.text());
println!("> {}", comment.text());
println!();
}); ```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.