use html_extractor::*;
pub async fn get_url() -> Result<String, Error> {
let html = reqwest::get("https://www.bing.com/").await?.text().await?;
let bing = BingTopPage::extract_from_str(&html)?;
match &*bing.wallpaper_url {
"#" => Err(Error::NotAvailable),
url => Ok(format!(
"https://www.bing.com{}",
url.replace("qlt=50", "qlt=100")
)),
}
}
html_extractor! {
BingTopPage {
wallpaper_url: String = (attr["href"] of "#preloadBg"),
}
}
#[derive(Debug)]
pub enum Error {
Network(reqwest::Error),
InvalidResponse(html_extractor::Error),
NotAvailable,
}
impl From<reqwest::Error> for Error {
fn from(e: reqwest::Error) -> Self {
Error::Network(e)
}
}
impl From<html_extractor::Error> for Error {
fn from(e: html_extractor::Error) -> Self {
Error::InvalidResponse(e)
}
}