1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use log::{info, log_enabled, Level};
use reqwest::Client;
use reqwest::StatusCode;
pub async fn fetch_page_html(url: &str, client: &Client) -> String {
match client.get(url).send().await {
Ok(res) if res.status() == StatusCode::OK => match res.text().await {
Ok(text) => text,
Err(_) => {
log("- error fetching {}", &url);
String::new()
}
},
Ok(_) => String::new(),
Err(_) => {
log("- error parsing html text {}", &url);
String::new()
}
}
}
pub fn log(message: &'static str, data: impl AsRef<str>) {
if log_enabled!(Level::Info) {
info!("{message} - {}", data.as_ref());
}
}