因为在java上习惯了使用了jsoup解析抓取到的网页,在rust的crate.io中搜索jquery,首先出来的就是crabquery,猛一用,感觉还行,用着用着就发现实现在简单了,功能很少,很基础,但胜的名字误导人,又翻了翻才找到了下面这个库https://docs.rs/nipper/0.1.8/nipper/,而且还是国人开发的。大致用了下,功能和jsoup差不多。
use nipper::Document;
fn main() {
let html = include_str!("../test-pages/hacker_news.html");
let document = Document::from(html);
document.select("tr.athing").iter().for_each(|athing| {
let title = athing.select(".title a");
let href = athing.select(".storylink");
println!("{}", title.text());
println!("{}", href.attr("href").unwrap());
println!();
});
}