pub struct Selector { /* private fields */ }Expand description
Wrapper around CSS selectors.
Represents a “selector group”, i.e. a comma-separated list of selectors.
Implementations§
source§impl Selector
impl Selector
sourcepub fn parse(selectors: &str) -> Result<Self, SelectorErrorKind<'_>>
pub fn parse(selectors: &str) -> Result<Self, SelectorErrorKind<'_>>
Parses a CSS selector group.
Examples found in repository?
examples/document.rs (line 15)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
fn main() {
let mut input = String::new();
let mut stdout = io::stdout();
let mut stdin = io::stdin();
write!(stdout, "CSS selector: ").unwrap();
stdout.flush().unwrap();
stdin.read_line(&mut input).unwrap();
let selector = Selector::parse(&input).unwrap();
write!(stdout, "HTML document:\n").unwrap();
stdout.flush().unwrap();
input.clear();
stdin.read_to_string(&mut input).unwrap();
let document = Html::parse_document(&input);
println!("{:#?}", document);
for node in document.select(&selector) {
println!("{:?}", node.value());
}
}More examples
examples/fragment.rs (line 15)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
fn main() {
let mut input = String::new();
let mut stdout = io::stdout();
let mut stdin = io::stdin();
write!(stdout, "CSS selector: ").unwrap();
stdout.flush().unwrap();
stdin.read_line(&mut input).unwrap();
let selector = Selector::parse(&input).unwrap();
write!(stdout, "HTML fragment:\n").unwrap();
stdout.flush().unwrap();
input.clear();
stdin.read_to_string(&mut input).unwrap();
let fragment = Html::parse_fragment(&input);
println!("{:#?}", fragment);
for node in fragment.select(&selector) {
println!("{:?}", node.value());
}
}sourcepub fn matches(&self, element: &ElementRef<'_>) -> bool
pub fn matches(&self, element: &ElementRef<'_>) -> bool
Returns true if the element matches this selector.
sourcepub fn matches_with_scope(
&self,
element: &ElementRef<'_>,
scope: Option<ElementRef<'_>>
) -> bool
pub fn matches_with_scope( &self, element: &ElementRef<'_>, scope: Option<ElementRef<'_>> ) -> bool
Returns true if the element matches this selector.
The optional scope argument is used to specify which element has :scope pseudo-class.
When it is None, :scope will match the root element.