Struct fast_scraper::element_ref::ElementRef
source · pub struct ElementRef<'a> { /* private fields */ }
Expand description
Wrapper around a reference to an element node.
This wrapper implements the Element
trait from the selectors
crate, which allows it to be
matched against CSS selectors.
Implementations§
source§impl<'a> ElementRef<'a>
impl<'a> ElementRef<'a>
sourcepub fn wrap(node: NodeRef<'a, Node>) -> Option<Self>
pub fn wrap(node: NodeRef<'a, Node>) -> Option<Self>
Wraps a NodeRef
only if it references a Node::Element
.
sourcepub fn value(&self) -> &'a Element
pub fn value(&self) -> &'a Element
Returns the Element
referenced by self
.
Examples found in repository?
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 stdout = io::stdout();
let mut input = String::new();
let 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_line(&mut input).unwrap();
let document = Html::parse_document(&input);
println!("{:#?}", document);
for node in document.select(&selector) {
println!("{:?}", node.value());
}
}
More examples
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
let mut stdout = io::stdout();
let mut input = String::new();
let 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_line(&mut input).unwrap();
let fragment = Html::parse_fragment(&input);
println!("{:#?}", fragment);
for node in fragment.select(&selector) {
println!("{:?}", node.value());
}
}
sourcepub fn select<'b>(&self, selector: &'b Selector) -> Select<'a, 'b> ⓘ
pub fn select<'b>(&self, selector: &'b Selector) -> Select<'a, 'b> ⓘ
Returns an iterator over descendent elements matching a selector.
sourcepub fn inner_html(&self) -> String
pub fn inner_html(&self) -> String
Returns the inner HTML of this element.
Methods from Deref<Target = NodeRef<'a, Node>>§
sourcepub fn prev_sibling(&self) -> Option<NodeRef<'a, T>>
pub fn prev_sibling(&self) -> Option<NodeRef<'a, T>>
Returns the previous sibling of this node.
sourcepub fn next_sibling(&self) -> Option<NodeRef<'a, T>>
pub fn next_sibling(&self) -> Option<NodeRef<'a, T>>
Returns the next sibling of this node.
sourcepub fn first_child(&self) -> Option<NodeRef<'a, T>>
pub fn first_child(&self) -> Option<NodeRef<'a, T>>
Returns the first child of this node.
sourcepub fn last_child(&self) -> Option<NodeRef<'a, T>>
pub fn last_child(&self) -> Option<NodeRef<'a, T>>
Returns the last child of this node.
sourcepub fn has_siblings(&self) -> bool
pub fn has_siblings(&self) -> bool
Returns true if this node has siblings.
sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true if this node has children.
sourcepub fn prev_siblings(&self) -> PrevSiblings<'a, T>
pub fn prev_siblings(&self) -> PrevSiblings<'a, T>
Returns an iterator over previous siblings.
sourcepub fn next_siblings(&self) -> NextSiblings<'a, T>
pub fn next_siblings(&self) -> NextSiblings<'a, T>
Returns an iterator over next siblings.
sourcepub fn first_children(&self) -> FirstChildren<'a, T>
pub fn first_children(&self) -> FirstChildren<'a, T>
Returns an iterator over first children.
sourcepub fn last_children(&self) -> LastChildren<'a, T>
pub fn last_children(&self) -> LastChildren<'a, T>
Returns an iterator over last children.
sourcepub fn traverse(&self) -> Traverse<'a, T>
pub fn traverse(&self) -> Traverse<'a, T>
Returns an iterator which traverses the subtree starting at this node.
sourcepub fn descendants(&self) -> Descendants<'a, T>
pub fn descendants(&self) -> Descendants<'a, T>
Returns an iterator over this node and its descendants.
Trait Implementations§
source§impl<'a> Clone for ElementRef<'a>
impl<'a> Clone for ElementRef<'a>
source§fn clone(&self) -> ElementRef<'a>
fn clone(&self) -> ElementRef<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for ElementRef<'a>
impl<'a> Debug for ElementRef<'a>
source§impl<'a> Deref for ElementRef<'a>
impl<'a> Deref for ElementRef<'a>
source§impl<'a> Element for ElementRef<'a>
impl<'a> Element for ElementRef<'a>
Note: will never match against non-tree-structure pseudo-classes.
type Impl = Simple
source§fn opaque(&self) -> OpaqueElement
fn opaque(&self) -> OpaqueElement
fn parent_element(&self) -> Option<Self>
source§fn parent_node_is_shadow_root(&self) -> bool
fn parent_node_is_shadow_root(&self) -> bool
source§fn containing_shadow_host(&self) -> Option<Self>
fn containing_shadow_host(&self) -> Option<Self>
source§fn is_pseudo_element(&self) -> bool
fn is_pseudo_element(&self) -> bool
fn is_part(&self, _name: &CssLocalName) -> bool
source§fn is_same_type(&self, other: &Self) -> bool
fn is_same_type(&self, other: &Self) -> bool
other
element have the same local name and namespace.source§fn imported_part(&self, _: &CssLocalName) -> Option<CssLocalName>
fn imported_part(&self, _: &CssLocalName) -> Option<CssLocalName>
exportparts
attribute in the reverse
direction, that is, in an outer-tree -> inner-tree direction.source§fn prev_sibling_element(&self) -> Option<Self>
fn prev_sibling_element(&self) -> Option<Self>
source§fn next_sibling_element(&self) -> Option<Self>
fn next_sibling_element(&self) -> Option<Self>
fn is_html_element_in_html_document(&self) -> bool
fn has_local_name(&self, name: &CssLocalName) -> bool
source§fn has_namespace(&self, namespace: &Namespace) -> bool
fn has_namespace(&self, namespace: &Namespace) -> bool
fn attr_matches( &self, ns: &NamespaceConstraint<&Namespace>, local_name: &CssLocalName, operation: &AttrSelectorOperation<&CssString> ) -> bool
fn match_non_ts_pseudo_class<F>( &self, _pc: &NonTSPseudoClass, _context: &mut MatchingContext<'_, Self::Impl>, _flags_setter: &mut F ) -> bool
fn match_pseudo_element( &self, _pe: &PseudoElement, _context: &mut MatchingContext<'_, Self::Impl> ) -> bool
source§fn is_html_slot_element(&self) -> bool
fn is_html_slot_element(&self) -> bool
fn has_id(&self, id: &CssLocalName, case_sensitivity: CaseSensitivity) -> bool
fn has_class( &self, name: &CssLocalName, case_sensitivity: CaseSensitivity ) -> bool
source§fn is_root(&self) -> bool
fn is_root(&self) -> bool
:root
,
i.e. whether it is the root element of a document. Read moresource§fn pseudo_element_originating_element(&self) -> Option<Self>
fn pseudo_element_originating_element(&self) -> Option<Self>
source§fn assigned_slot(&self) -> Option<Self>
fn assigned_slot(&self) -> Option<Self>
source§fn ignores_nth_child_selectors(&self) -> bool
fn ignores_nth_child_selectors(&self) -> bool
source§impl<'a> PartialEq<ElementRef<'a>> for ElementRef<'a>
impl<'a> PartialEq<ElementRef<'a>> for ElementRef<'a>
source§fn eq(&self, other: &ElementRef<'a>) -> bool
fn eq(&self, other: &ElementRef<'a>) -> bool
self
and other
values to be equal, and is used
by ==
.