pub struct Element { /* private fields */ }

Implementations

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");

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");

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");

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");

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");

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

Converts to this type from the input type.

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.