search_attr/
search_attr.rs

1use parsercher;
2
3fn main() {
4    let html = r#"
5    <!DOCTYPE html>
6    <html>
7      <head>
8        <meta charset="UTF-8">
9        <meta target="value1">
10        <title>sample html</title>
11      </head>
12      <body target="value2">
13        <h1>sample</h1>
14
15        <div id="content" target="value3"></div>
16
17        <ol>
18          <li>first</li>
19          <li target="value4">second</li>
20          <li>therd</li>
21        </ol>
22      </body>
23    </html>
24    "#;
25
26    let dom = parsercher::parse(&html).unwrap();
27
28    let values = parsercher::search_attr(&dom, "target").unwrap();
29    assert_eq!(values.len(), 4);
30    assert_eq!(values[0], "value1".to_string());
31    assert_eq!(values[1], "value2".to_string());
32    assert_eq!(values[2], "value3".to_string());
33    assert_eq!(values[3], "value4".to_string());
34}