pub fn search_attr(dom: &Dom, attr: &str) -> Option<Vec<String>>
Expand description
Returns the value of a specific attribute for all tags.
ยงExamples
Get the value of the target
attribute of all tags.
use parsercher;
let html = r#"
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta target="value1">
<title>sample html</title>
</head>
<body target="value2">
<h1>sample</h1>
<div id="content" target="value3"></div>
<ol>
<li>first</li>
<li target="value4">second</li>
<li>therd</li>
</ol>
</body>
</html>
"#;
let dom = parsercher::parse(&html).unwrap();
let values = parsercher::search_attr(&dom, "target").unwrap();
assert_eq!(values.len(), 4);
assert_eq!(values[0], "value1".to_string());
assert_eq!(values[1], "value2".to_string());
assert_eq!(values[2], "value3".to_string());
assert_eq!(values[3], "value4".to_string());
Examples found in repository?
examples/search_attr.rs (line 28)
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}