pub struct Selection<'a> { /* private fields */ }Expand description
A collection of matched nodes from a selector query.
Provides iteration, text extraction, attribute access, and sub-selection (chaining).
Implementations§
Source§impl<'a> Selection<'a>
impl<'a> Selection<'a>
Sourcepub fn iter(&self) -> impl Iterator<Item = NodeRef<'a>> + '_
pub fn iter(&self) -> impl Iterator<Item = NodeRef<'a>> + '_
Iterate over matched nodes as NodeRef.
Sourcepub fn attr(&self, name: &str) -> Option<&'a str>
pub fn attr(&self, name: &str) -> Option<&'a str>
Get an attribute value from the first matched node.
Sourcepub fn inner_html(&self) -> String
pub fn inner_html(&self) -> String
Get inner HTML from the first matched node.
Sourcepub fn select_compiled(
&self,
sel: &CompiledSelector,
) -> Result<Selection<'a>, SelectorError>
pub fn select_compiled( &self, sel: &CompiledSelector, ) -> Result<Selection<'a>, SelectorError>
Sub-select with a pre-compiled selector within the matched nodes.
Each matched node is used as a subtree root, and results are deduplicated in document order.
Sourcepub fn select(&self, css: &str) -> Result<Selection<'a>, SelectorError>
pub fn select(&self, css: &str) -> Result<Selection<'a>, SelectorError>
Sub-select: run a CSS selector within the matched nodes.
Each matched node is used as a subtree root, and results are deduplicated in document order.
Sourcepub fn xpath(&self, expr: &str) -> Result<XPathResult, XPathError>
pub fn xpath(&self, expr: &str) -> Result<XPathResult, XPathError>
Evaluate an XPath expression within the matched nodes.
Each matched node is used as a context root, and results are deduplicated in document order.
Note: the leading // is evaluated relative to each matched node’s
subtree (descendant-or-self), not against the whole document. So
doc.select("div").xpath("//span") finds the spans inside each matched
div, and an axis like //div also yields the context div itself.
This scoping is intentional so XPath composes with a prior selection;
for a document-wide query, evaluate from the document root instead.