Add a function for fetching page titles

This commit is contained in:
Manuel Thalmann 2025-04-03 08:21:51 +02:00
parent 22c73843bc
commit c3e466fc23
Signed by: manuth
SSH key fingerprint: SHA256:HsMLC+7kJWALP6YCYCoopxNbUnghwSGLVcG76SECT5c
3 changed files with 2132 additions and 0 deletions

2121
hello-async/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2024"
[dependencies]
trpl = "0.2.0"

View file

@ -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())
}