[][src]Struct crabquery::Element

pub struct Element { /* fields omitted */ }

Methods

impl Element[src]

pub fn attr(&self, name: &str) -> Option<String>[src]

Get value of an attribue

Arguments

  • name - attribute name

Example

use crabquery::Document;

let doc = Document::from("<a class='link'>hi there</a>");
let sel = doc.select("a");
let el = sel.first().unwrap();

assert_eq!(el.attr("class").unwrap(), "link");

pub fn tag(&self) -> Option<String>[src]

Get tag value

Example

use crabquery::Document;

let doc = Document::from("<a class='link'>hi there</a>");
let sel = doc.select("a");
let el = sel.first().unwrap();

assert_eq!(el.tag().unwrap(), "a");

pub fn text(&self) -> Option<String>[src]

Get text

Example

use crabquery::Document;

let doc = Document::from("<a class='link'>hi there</a>");
let sel = doc.select("a");
let el = sel.first().unwrap();

assert_eq!(el.text().unwrap(), "hi there");

pub fn children(&self) -> Vec<Element>[src]

Get children elements

Example

use crabquery::Document;

let doc = Document::from("<a class='link'><span>hi there</span></a>");
let sel = doc.select("a");
let el = sel.first().unwrap();

assert_eq!(el.children().first().unwrap().text().unwrap(), "hi there");

pub fn parent(&self) -> Option<Element>[src]

Get parent element

Example

use crabquery::Document;

let doc = Document::from("<a class='link'><span>hi there</span></a>");
let sel = doc.select("span");
let el = sel.first().unwrap();

assert_eq!(el.parent().unwrap().tag().unwrap(), "a");

pub fn select(&self, selector: &str) -> Vec<Element>[src]

Select child elements using given css selector

Example

use crabquery::Document;

let doc = Document::from("<span><a class='link'>hi there</a></span>");
let sel = doc.select("span");
let el = sel.first().unwrap();
let sel = el.select("a");
let a = sel.first().unwrap();

assert_eq!(a.attr("class").unwrap(), "link");

Trait Implementations

impl<'_> From<&'_ Arc<Node>> for Element[src]

impl From<Arc<Node>> for Element[src]

Auto Trait Implementations

impl !RefUnwindSafe for Element

impl !Send for Element

impl !Sync for Element

impl Unpin for Element

impl !UnwindSafe for Element

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.