Add more logic for konsumentinfo.se, telefonforsaljare.nu, and handle error for hitta.se.
This commit is contained in:
@@ -28,9 +28,12 @@ impl Probe for Eniro {
|
|||||||
ctx.cache_set("eniro", &number, body.as_bytes())
|
ctx.cache_set("eniro", &number, body.as_bytes())
|
||||||
.expect("wut?! why not?!");
|
.expect("wut?! why not?!");
|
||||||
|
|
||||||
if let Ok(error) = Error::from_html(&body) {
|
|
||||||
println!("eniro.se:");
|
println!("eniro.se:");
|
||||||
|
|
||||||
|
if let Ok(error) = Error::from_html(&body) {
|
||||||
println!(" {}", error.message);
|
println!(" {}", error.message);
|
||||||
|
} else {
|
||||||
|
println!(" Failed to find any data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,20 +61,17 @@ impl Probe for Hitta {
|
|||||||
if let Some(result) = re.captures(&body) {
|
if let Some(result) = re.captures(&body) {
|
||||||
let json = result.get(1).unwrap().as_str();
|
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!("hitta.se:");
|
||||||
|
|
||||||
|
if let Ok(data) = serde_json::from_str::<Data>(&json) {
|
||||||
println!(" {}", data.props.page_props.phone_data.statistics_text);
|
println!(" {}", data.props.page_props.phone_data.statistics_text);
|
||||||
|
|
||||||
for comment in &data.props.page_props.phone_data.comments {
|
for comment in &data.props.page_props.phone_data.comments {
|
||||||
println!(" * {}", comment.comment);
|
println!(" * {}", comment.comment);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
println!(" Failed to find any data");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
|
use unhtml::FromHtml;
|
||||||
|
use unhtml_derive::FromHtml;
|
||||||
|
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::probe::Probe;
|
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/{}
|
// http://konsumentinfo.se/telefonnummer/sverige/{}
|
||||||
pub struct KonsumentInfo;
|
pub struct KonsumentInfo;
|
||||||
|
|
||||||
@@ -20,5 +30,13 @@ impl Probe for KonsumentInfo {
|
|||||||
|
|
||||||
ctx.cache_set("konsument_info", &number, body.as_bytes())
|
ctx.cache_set("konsument_info", &number, body.as_bytes())
|
||||||
.expect("wut?! why not?!");
|
.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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
|
use unhtml::FromHtml;
|
||||||
|
use unhtml_derive::FromHtml;
|
||||||
|
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::probe::Probe;
|
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/{}/
|
// http://www.telefonforsaljare.nu/telefonnummer/{}/
|
||||||
pub struct Telefonforsaljare;
|
pub struct Telefonforsaljare;
|
||||||
|
|
||||||
@@ -20,5 +30,13 @@ impl Probe for Telefonforsaljare {
|
|||||||
|
|
||||||
ctx.cache_set("telefonforsaljare", &number, body.as_bytes())
|
ctx.cache_set("telefonforsaljare", &number, body.as_bytes())
|
||||||
.expect("wut?! why not?!");
|
.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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user