Skip to main content

Crate html_meta_scraper

Crate html_meta_scraper 

Source
Expand description

Extract metadata from an HTML document — <title>, OpenGraph and Twitter Card tags, favicon, and the root <html lang> attribute.

This crate parses HTML strings you provide; it does not fetch URLs.

§Example

use html_meta_scraper::MetaScraper;

let html = r#"
    <html lang="en">
        <head>
            <title>Native Title</title>
            <meta property="og:title" content="OG Title" />
            <meta property="og:image" content="https://example.com/cover.jpg" />
        </head>
    </html>
"#;

let m = MetaScraper::new(html);
assert_eq!(m.title().as_deref(), Some("OG Title"));
assert_eq!(m.image().as_deref(), Some("https://example.com/cover.jpg"));
assert_eq!(m.lang().as_deref(), Some("en"));

Structs§

MetaScraper
Holds a parsed HTML document and exposes accessors for common page metadata.