h2s
A declarative HTML parser library in Rust, which works like a deserializer from HTML to struct.
Example
use FromHtml;
let html = r#"
<html lang="en">
<body>
<div>
<h1 class="blog-title">My tech blog</h1>
<div class="articles">
<div>
<h2><a href="https://example.com/1">article1</a></h2>
<div><span>901</span> Views</div>
<ul><li>Tag1</li><li>Tag2</li></ul>
</div>
<div>
<h2><a href="https://example.com/2">article2</a></h2>
<div><span>849</span> Views</div>
<ul></ul>
</div>
<div>
<h2><a href="https://example.com/3">article3</a></h2>
<div><span>103</span> Views</div>
<ul><li>Tag3</li></ul>
</div>
</div>
</div>
</body>
</html>
"#;
let page = .unwrap;
assert_eq!;
// When the input HTML document structure does not match the expected,
// `h2s::parse` will return an error with a detailed reason.
let invalid_html = html.replace;
let err = .unwrap_err;
assert_eq!;
Supported types
You can use the following types as a field value of the struct to parse.
Basic types
String- Numeric types (
usize,i64,NonZeroU32, ... ) - And more built-in supported types (List)
- Or you can use any types by implementing yourself (Example)
Container types (where T is a basic type)
[T;N]Option<T>Vec<T>
License
MIT