extract

Function extract 

Source
pub fn extract(html: &str, spec: &Spec) -> Result<Value>
Expand description

Extract JSON from HTML using a spec

§Arguments

  • html - The HTML source to parse
  • spec - The extraction specification

§Example

use html2json::{extract, Spec};

let html = r#"<div class="item"><span>Price: $25.00</span></div>"#;
let spec_json = r#"{"price": ".item span | regex:\\$(\\d+\\.\\d+)"}"#;
let spec: Spec = serde_json::from_str(spec_json)?;
let result = extract(html, &spec)?;
assert_eq!(result["price"], "25.00");