[Feature Request] Find by Text
seongs1024 opened this issue · 1 comments
seongs1024 commented
In the case, select tags which are siblings of a tag containing some text.
I don't have clue to do that...
It would be great to have a method, find by name, like BeautifulSoup.
Thank you
seongs1024 commented
To get text of the sibling, this code works but look bad to me
fn find(html: &str, selector: Arc<Selector>, text: &str) -> String {
let document = Html::parse_fragment(&html);
document
.select(&selector)
.filter(|e| {
let trimed = e.text().next().map(|e| e.trim());
trimed == Some(text)
})
.flat_map(|e| e.next_sibling_element())
.map(|e| e.text().collect::<String>())
.map(|s| s.trim().to_string())
.collect()
}