use anyhow::{Result}; use scraper; use std::string::String; /// Extract element text, trimmed of whitespace. fn element_text(element: scraper::ElementRef<'_>) -> String { let text = element .text() .map(|s| s.trim_matches(char::is_whitespace)) .filter(|x| !x.is_empty()) .collect::(); text } pub fn find_useragents(html: &str) -> Result> { let mut result = Vec::::new(); let document = scraper::Html::parse_document(&html); let select = scraper::Selector::parse(r#"li > span[class="code"]"#).unwrap(); for s in document.select(&select) { result.push(element_text(s)) } Ok(result) }