init
This commit is contained in:
22
src/web_parser.rs
Normal file
22
src/web_parser.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use scraper::{Html, Selector};
|
||||
use crate::{file, get_response};
|
||||
|
||||
pub(crate) fn get_html_title(body: String) -> String {
|
||||
let document = Html::parse_document(&body);
|
||||
let title_selector = Selector::parse("h1").unwrap();
|
||||
let title_element = document.select(&title_selector).next().unwrap();
|
||||
return title_element.text().next().unwrap().to_string();
|
||||
}
|
||||
|
||||
pub(crate) fn download_image(url_path: &str, file_path: &str) -> bool {
|
||||
let url = format!("https://i.tuiimg.net/{}", url_path);
|
||||
println!("{}",url);
|
||||
let response = get_response(&url);
|
||||
if response.is_empty() {
|
||||
return false
|
||||
}
|
||||
let file_path = format!("images/{}", file_path);
|
||||
println!("{}",file_path);
|
||||
file::write_file(&file_path, response).expect("Write file error");
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user