mirror of
https://github.com/darkicewolf50/RustBrock.git
synced 2025-07-06 19:17:14 -06:00
finshed ch17.1
This commit is contained in:
21
hello-async/src/main.rs
Normal file
21
hello-async/src/main.rs
Normal file
@ -0,0 +1,21 @@
|
||||
extern crate trpl;
|
||||
use trpl::Html;
|
||||
|
||||
async fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let url = &args[1];
|
||||
match page_title(url).await {
|
||||
Some(title) => println!("The title for {url} was {title}"),
|
||||
None => println!("{url} had no title"),
|
||||
}
|
||||
}
|
||||
|
||||
async fn page_title(url: &str) -> Option<String> {
|
||||
let res = trpl::get(url).await;
|
||||
|
||||
let res_text = res.text().await;
|
||||
|
||||
Html::parse(&res_text)
|
||||
.select_first("title")
|
||||
.map(|title_element| title_element.inner_html())
|
||||
}
|
Reference in New Issue
Block a user