1 个稳定版本
1.0.1 | 2020年6月17日 |
---|
#11 in #request-builder
17KB
228 行
easy_rss
使用 Rust 序列化 RSS 结构。
用法
easy_rss = "*"
示例
解析 Xml
use easy_rss::*;
fn main()->Result<(),Box<dyn std::error::Error>> {
let address = "https://www.zhihu.com/rss";
let mut parser = RssParser::from_url(address,"utf8")?;
parser.author_tag = String::from("dc:creator");
let rss = parser.parse_vec()?;
println!("{:?}",rss);
Ok(())
}
解析 Web XMl
use easy_rss::RssParser;
fn main()->Result<(),Box<dyn std::error::Error>> {
let address = "https://www.zhihu.com/rss";
let mut parser = RssParser::from_url(address,"utf8")?;
parser.author_tag = String::from("dc:creator");
assert!(parser.parse_json().is_ok());
Ok(())
}
RSS 转 Json
use easy_rss::RssParser;
fn main()->Result<(),Box<dyn std::error::Error>> {
let address = "https://www.zhihu.com/rss";
let mut parser = RssParser::from_url(address,"utf8")?;
parser.author_tag = String::from("dc:creator");
assert!(parser.parse_json().is_ok());
Ok(())
}
Rss 请求构建器
use easy_rss::RssParser;
fn main()->Result<(),Box<dyn std::error::Error>> {
let address = "https://www.zhihu.com/rss";
let mut parser = RssParser::new();
parser.author_tag = "dc:creator".into();
parser.publish_tag = "pubDate".into();
let xml = parser.request_xml(address.as_str(),charset.as_str())?;
parser.set_xml(xml);
assert!(parser.parse_vec().is_ok());
Ok(())
}
高级
依赖项
~4–8MB
~171K SLoC