diff --git a/src/probe/eniro.rs b/src/probe/eniro.rs index a31b0cb..b03917f 100644 --- a/src/probe/eniro.rs +++ b/src/probe/eniro.rs @@ -28,9 +28,12 @@ impl Probe for Eniro { ctx.cache_set("eniro", &number, body.as_bytes()) .expect("wut?! why not?!"); + println!("eniro.se:"); + if let Ok(error) = Error::from_html(&body) { - println!("eniro.se:"); println!(" {}", error.message); + } else { + println!(" Failed to find any data"); } } } diff --git a/src/probe/hitta.rs b/src/probe/hitta.rs index 48270b2..cfe4934 100644 --- a/src/probe/hitta.rs +++ b/src/probe/hitta.rs @@ -61,19 +61,16 @@ impl Probe for Hitta { if let Some(result) = re.captures(&body) { let json = result.get(1).unwrap().as_str(); - /* - let data: serde_json::Value = serde_json::from_str(&json).unwrap(); - - println!("{:#?}", data); - */ - - let data: Data = serde_json::from_str(&json).unwrap(); - println!("hitta.se:"); - println!(" {}", data.props.page_props.phone_data.statistics_text); - for comment in &data.props.page_props.phone_data.comments { - println!(" * {}", comment.comment); + if let Ok(data) = serde_json::from_str::(&json) { + println!(" {}", data.props.page_props.phone_data.statistics_text); + + for comment in &data.props.page_props.phone_data.comments { + println!(" * {}", comment.comment); + } + } else { + println!(" Failed to find any data"); } } } diff --git a/src/probe/konsument_info.rs b/src/probe/konsument_info.rs index 1f10d61..b7bf1f9 100644 --- a/src/probe/konsument_info.rs +++ b/src/probe/konsument_info.rs @@ -1,6 +1,16 @@ +use unhtml::FromHtml; +use unhtml_derive::FromHtml; + use crate::context::Context; use crate::probe::Probe; +#[derive(Debug, FromHtml)] +#[html(selector = ".panel-body")] +struct Info { + #[html(selector = "h4", attr = "inner")] + message: String, +} + // http://konsumentinfo.se/telefonnummer/sverige/{} pub struct KonsumentInfo; @@ -20,5 +30,13 @@ impl Probe for KonsumentInfo { ctx.cache_set("konsument_info", &number, body.as_bytes()) .expect("wut?! why not?!"); + + println!("konsumentinfo.se:"); + + if let Ok(info) = Info::from_html(&body) { + println!(" {}", info.message); + } else { + println!(" Failed to find any data"); + } } } diff --git a/src/probe/telefonforsaljare.rs b/src/probe/telefonforsaljare.rs index 0a10b5a..c19032c 100644 --- a/src/probe/telefonforsaljare.rs +++ b/src/probe/telefonforsaljare.rs @@ -1,6 +1,16 @@ +use unhtml::FromHtml; +use unhtml_derive::FromHtml; + use crate::context::Context; use crate::probe::Probe; +#[derive(Debug, FromHtml)] +#[html(selector = "[itemtype='//data-vocabulary.org/Review-aggregate']")] +struct Info { + #[html(selector = "p", attr = "inner")] + message: String, +} + // http://www.telefonforsaljare.nu/telefonnummer/{}/ pub struct Telefonforsaljare; @@ -20,5 +30,13 @@ impl Probe for Telefonforsaljare { ctx.cache_set("telefonforsaljare", &number, body.as_bytes()) .expect("wut?! why not?!"); + + println!("telefonforsaljare.nu:"); + + if let Ok(info) = Info::from_html(&body) { + println!(" {}", info.message); + } else { + println!(" Failed to find any data"); + } } }