blob: 734d33b4902d8cb413429d167a2531525d589656 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#![allow(dead_code)]
use select::document::Document;
use select::node::Node;
use select::predicate::Name;
use select::predicate::Predicate;
/// Return the href attribute content for the closest anchor found by `text`.
pub fn get_link_from_text(document: &Document, text: &str) -> Option<String> {
let a_elem = document
.find(Name("a").and(|x: &Node| x.children().any(|x| x.text() == text)))
.next()?;
Some(a_elem.attr("href")?.to_string())
}
|