tyupy 1.1.0

Get URL(s) title in any format
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use reqwest::Client;
use select::{document::Document, predicate::Name};
use url::Url;

pub async fn title(url: &Url) -> Result<String, crate::Error> {
    let response = Client::new().get(url.to_string()).send().await?;
    let body = response.text().await?;

    let document = Document::from_read(body.as_bytes())?;

    let title = document
        .find(Name("title"))
        .next()
        .map(|title_node| title_node.text())
        .unwrap_or_else(|| "No title found".to_string());

    Ok(title)
}