pub struct Html {
pub errors: Vec<Cow<'static, str>>,
pub quirks_mode: QuirksMode,
pub tree: Tree<Node>,
}Expand description
An HTML tree.
Parsing does not fail hard. Instead, the quirks_mode is set and errors are added to the
errors field. The tree will still be populated as best as possible.
Implements the TreeSink trait from the html5ever crate, which allows HTML to be parsed.
Fields§
§errors: Vec<Cow<'static, str>>Parse errors.
quirks_mode: QuirksModeThe quirks mode.
tree: Tree<Node>The node tree.
Implementations§
Source§impl Html
impl Html
Sourcepub fn new_document() -> Html
pub fn new_document() -> Html
Creates an empty HTML document.
Sourcepub fn new_fragment() -> Html
pub fn new_fragment() -> Html
Creates an empty HTML fragment.
Sourcepub fn parse_document(document: &str) -> Html
pub fn parse_document(document: &str) -> Html
Parses a string of HTML as a document.
This is a convenience method for the following:
use html5ever::driver::{self, ParseOpts};
use scraper::{Html, HtmlTreeSink};
use tendril::TendrilSink;
let parser = driver::parse_document(HtmlTreeSink::new(Html::new_document()), ParseOpts::default());
let html = parser.one(document);Sourcepub fn parse_fragment(fragment: &str) -> Html
pub fn parse_fragment(fragment: &str) -> Html
Parses a string of HTML as a fragment.
Sourcepub fn select<'a, 'b>(&'a self, selector: &'b Selector) -> Select<'a, 'b>
pub fn select<'a, 'b>(&'a self, selector: &'b Selector) -> Select<'a, 'b>
Returns an iterator over elements matching a selector.
Sourcepub fn root_element(&self) -> ElementRef<'_>
pub fn root_element(&self) -> ElementRef<'_>
Returns the root <html> element.
Trait Implementations§
Source§impl<'a> Selectable<'a> for &'a Html
impl<'a> Selectable<'a> for &'a Html
Source§impl Serialize for Html
impl Serialize for Html
Source§fn serialize<S>(
&self,
serializer: &mut S,
traversal_scope: TraversalScope,
) -> Result<(), Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: &mut S,
traversal_scope: TraversalScope,
) -> Result<(), Error>where
S: Serializer,
Take the serializer and call its methods to serialize this type. The type will dictate
which methods are called and with what parameters.
impl Eq for Html
impl StructuralPartialEq for Html
Auto Trait Implementations§
impl Freeze for Html
impl !RefUnwindSafe for Html
impl !Send for Html
impl !Sync for Html
impl Unpin for Html
impl UnwindSafe for Html
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.