Add a function for fetching page titles
This commit is contained in:
parent
22c73843bc
commit
c3e466fc23
3 changed files with 2132 additions and 0 deletions
hello-async
2121
hello-async/Cargo.lock
generated
2121
hello-async/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -4,3 +4,4 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
trpl = "0.2.0"
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
use trpl::Html;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
async fn page_title(url: &str) -> Option<String> {
|
||||
let response = trpl::get(url).await;
|
||||
let response_text = response.text().await;
|
||||
Html::parse(&response_text)
|
||||
.select_first("title")
|
||||
.map(|title_element| title_element.inner_html())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue