Add more logic for konsumentinfo.se, telefonforsaljare.nu, and handle error for hitta.se.

This commit is contained in:
2019-01-16 17:32:56 +01:00
parent e4a554a61b
commit e1a65df405
4 changed files with 48 additions and 12 deletions

View File

@@ -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");
}
}
}