opengraph-rs

Crates.ioopengraph-rs
lib.rsopengraph-rs
version0.2.6
sourcesrc
created_at2024-03-15 18:38:00.634499
updated_at2024-03-15 18:38:00.634499
descriptionParses html and extracts Open Graph protocol markup. Fork of https://github.com/kumabook/opengraph
homepagehttps://github.com/iamjagan/opengraph
repositoryhttps://github.com/iamjagan/opengraph.git
max_upload_size
id1175044
size17,039
(iamjagan)

documentation

README

opengraph

opengraph is a library that parses html and extracts Open Graph protocol markup.

Usage

  • Add opengraph to dependencies in Cargo.toml
[dependencies]
opengraph = "^0"
  • Then, use opengraph::scrape as below:

extern crate opengraph;

fn main() {
  match opengraph::scrape("https://spincoaster.com/chromeo-juice", Default::default()) {
      Ok(object) => {
          println!("{:?}", object);
      },
      Err(_) => println!("error occured"),
  }
}

or use opengraph::extract as below:

extern crate opengraph;

fn main() {
    let x = r#"
<html prefix="og: http://ogp.me/ns#">
<head>
<title>The Rock (1996)</title>
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
</head>
</html>
             "#;
    match opengraph::extract(&mut x.to_string().as_bytes(), Default::default()) {
        Ok(object) => {
            println!("{:?}", object);
        },
        Err(_) => println!("error occured"),
    }
}

License

MIT

Commit count: 0

cargo fmt