Webpage.rs

Get some info about a webpage

Usage

```rust extern crate webpage; use webpage::Webpage;

// ...

info = Webpage::from_url("http://www.rust-lang.org/en-US/");

// the HTTP info let http = info.http.unwrap();

asserteq!(http.ip, "54.192.129.71".tostring()); assert!(http.headers[0].startswith("HTTP")); assert!(http.body.startswith("")); asserteq!(http.url, "https://www.rust-lang.org/en-US/".tostring()); // followed redirects asserteq!(http.contenttype, "text/html".to_string());

// the HTML info let html = info.html.unwrap();

asserteq!(html.title.unwrap(), "The Rust Programming Language".tostring()); asserteq!(html.description.unwrap(), "A systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.".tostring()); asserteq!(html.opengraph.ogtype, "website".to_string()); ```

All fields

```rust pub struct Webpage { pub http: Option, // info about the HTTP transfer, if any pub html: Option, // info from the parsed HTML doc, if any }

pub struct HTTP { pub ip: String, pub transfertime: Duration, pub redirectcount: u32, pub contenttype: String, pub responsecode: u32, pub headers: Vec, // raw headers from final request pub url: String, // effective url pub body: String, }

pub struct HTML { pub title: Option, pub description: Option, pub url: Option,

pub language: Option<String>, // as specified, not detected
pub text_content: String, // all tags stripped from body

pub meta: HashMap<String, String>, // flattened down list of meta properties
pub opengraph: Opengraph,

}

pub struct Opengraph { pub og_type: String, pub properties: HashMap,

pub images: Vec<Object>,
pub videos: Vec<Object>,
pub audios: Vec<Object>,

}

pub struct OpengraphObject { pub url: String, pub properties: HashMap, } ```