Skip to main content

extract

Function extract 

Source
pub fn extract(html: &str, url: Option<&str>) -> Result<Article, Error>
Expand description

Parse HTML and extract the main article content in one call.

This is a convenience wrapper around Parser::new + Parser::parse. For repeated use or fine-grained configuration, create a Parser directly.

url is an optional page URL used to resolve relative links (e.g. "https://example.com/article"). Pass None if the HTML is self-contained or you don’t need absolute URLs.

§Errors

Returns Error::Parse if url is not a valid absolute URL, or if the HTML cannot be parsed into a readable article. Returns Error::NoContent or Error::NotReadable if no article content is found.

§Example

let article = libreadability::extract(
    "<html><body><article><p>Hello world</p></article></body></html>",
    None,
).unwrap();
assert_eq!(article.text_content, "Hello world");