I'm trying to get all the text on a HTML page, except for non-visible text (example: I don't want text inside script/style/noscript tags).
Here's what I've come up with so far:
let parser = kuchiki::parse_html().one(content);
for child in parser.inclusive_descendants() {
if let Some(el) = child.as_element() {
let tag_name = &el.name.local;
if tag_name == "script" || tag_name == "style" || tag_name == "noscript" {
child.detach();
}
}
}
let text = parser.text_contents();
println!("{}", text);
The idea is that the 1st pass will remove any script, style, or noscript tags. And then I can call text_contents to get the visible text.
However, it seems like text_contents is still returning inline Javascript.
Am I mis-understanding the Kuchiki/html5ever API?