MetaScraper

Struct MetaScraper 

Source
pub struct MetaScraper { /* private fields */ }

Implementations§

Source§

impl MetaScraper

Source

pub fn new(html: &str) -> Self

Source

pub fn extract_title(&self) -> Option<String>

Expected Output: "Page Title"

<title>Page Title</title>
Source

pub fn extract_og_title(&self) -> Option<String>

Expected Output: "Page Title"

<meta property="og:title" content="Page Title" />
Source

pub fn extract_twitter_title(&self) -> Option<String>

Expected Output: "Page Title"

<meta name="twitter:title" content="Page Title" />
Source

pub fn title(&self) -> Option<String>

Retrieves the page title.

Priority order:

  1. <meta property="og:title">
  2. <meta name="twitter:title">
  3. <title>

Returns the first one found.

Source

pub fn extract_description(&self) -> Option<String>

Expected Output: "My Description"

<meta name="description" content="My Description" />
Source

pub fn extract_og_description(&self) -> Option<String>

Expected Output: "My Description"

<meta property="og:description" content="My Description" />
Source

pub fn extract_twitter_description(&self) -> Option<String>

Expected Output: "My Description"

<meta name="twitter:description" content="My Description" />
Source

pub fn description(&self) -> Option<String>

Retrieves the page description.

Priority order:

  1. <meta property="og:description">
  2. <meta name="twitter:description">
  3. <meta name="description">

Returns the first one found.

Source

pub fn favicon(&self) -> Option<String>

Expected Output: "/favicon.ico"

<link rel="icon" href="/favicon.ico" />
Source

pub fn extract_og_image(&self) -> Option<String>

Expected Output: "https://example.com/image.jpg"

<meta property="og:image" content="https://example.com/image.jpg" />
Source

pub fn extract_og_images(&self) -> Vec<String>

Expected Output: ["https://example.com/image.jpg", "https://example.com/image.png"]

<meta property="og:image" content="https://example.com/image.jpg" />
<meta property="og:image" content="https://example.com/image.png" />
Source

pub fn extract_twitter_image(&self) -> Option<String>

Expected Output: "https://example.com/image.jpg"

<meta name="twitter:image" content="https://example.com/image.jpg" />
<meta name="twitter:image:alt" content="Image description" />
Source

pub fn image(&self) -> Option<String>

Retrieves the page image URL.

Priority order:

  1. <meta property="og:image">
  2. <meta name="twitter:image">

Returns the first one found.

Source

pub fn lang(&self) -> Option<String>

Expected Output: "en"

<html lang="en">
...
</html>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.