Crates.io | html-extractor |
lib.rs | html-extractor |
version | 1.0.0 |
source | src |
created_at | 2020-04-26 10:40:15.920812 |
updated_at | 2020-08-08 08:18:23.893838 |
description | A Rust crate for extracting data from HTML |
homepage | |
repository | https://github.com/mkihr-ojisan/html-extractor |
max_upload_size | |
id | 234221 |
size | 22,932 |
A Rust crate for extracting data from HTML.
use html_extractor::{html_extractor, HtmlExtractor};
html_extractor! {
#[derive(Debug, PartialEq)]
Foo {
foo: usize = (text of "#foo"),
}
}
fn main() {
let input = r#"
<div id="foo">1</div>
"#;
let foo = Foo::extract_from_str(input).unwrap();
assert_eq!(foo, Foo { foo: 1 });
}
use html_extractor::{html_extractor, HtmlExtractor};
html_extractor! {
#[derive(Debug, PartialEq)]
Foo {
foo: Vec<usize> = (text of ".foo", collect),
}
}
fn main() {
let input = r#"
<div class="foo">1</div>
<div class="foo">2</div>
<div class="foo">3</div>
<div class="foo">4</div>
"#;
let foo = Foo::extract_from_str(input).unwrap();
assert_eq!(foo, Foo { foo: vec![1, 2, 3, 4] });
}
use html_extractor::{html_extractor, HtmlExtractor};
html_extractor! {
#[derive(Debug, PartialEq)]
Foo {
(foo: usize,) = (text of "#foo", capture with "^foo=(.*)$"),
}
}
fn main() {
let input = r#"
<div id="foo">foo=1</div>
"#;
let foo = Foo::extract_from_str(input).unwrap();
assert_eq!(foo, Foo { foo: 1 });
}
presence of ..
target specifierinner_html
target specifier