我想在Rust中解析HTML.似乎这样做的一个库是html5ever.我找不到任何简单的方法来使它获取一个字符串并返回一个可查询对象.
是否有一个我可以使用的替代库,它接受一个字符串并返回一个我可以查询的对象?
我想在这里做网络抓取这样的事情.
我是一个完整的Rust新手.
cre*_*der 14
您可以使用select crate,它基本上是html5ever的包装器,但提供了更好的API.
例如:
use select::document::Document;
use select::predicate::Name;
for i in Document::from_str(html_src_string).find(Name("article")).iter() {
println!("{:?}",i.text() ); //prints text content of all articles
};
Run Code Online (Sandbox Code Playgroud)
select.rs存储库有更详细的示例.
| 归档时间: |
|
| 查看次数: |
3504 次 |
| 最近记录: |