extern crate reqwest; use reqwest::blocking::Client; use scraper::Html; use crate::parser; use crate::price_result::PriceResult; const USER_AGENT: &str = "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0"; pub struct PriceChecker { client: Client, parser_list: parser::List } impl PriceChecker { pub fn new() -> Self { let client = reqwest::blocking::Client::builder().user_agent(USER_AGENT).build().unwrap(); PriceChecker { client, parser_list: parser::List::new() } } pub fn get_price(&self, url : &str) -> PriceResult { let response = self.client.get(url).send().unwrap(); let text = response.text().unwrap(); let document = Html::parse_document(&text); for parser in self.parser_list.get().iter() { if parser.can_parse(url) { return parser.parse(&document); } } PriceResult { name: "name".to_owned(), product: "family".to_owned(), price: 0. } } }