Compare commits
4 commits
ac481ec06a
...
61619ac660
Author | SHA1 | Date | |
---|---|---|---|
61619ac660 | |||
314bc347de | |||
f1a4e2e819 | |||
108eb427b8 |
5 changed files with 29 additions and 7 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -226,7 +226,7 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
|||
|
||||
[[package]]
|
||||
name = "favicon-scraper"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"imagesize",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "favicon-scraper"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
description = "A favicon scraper that just works"
|
||||
|
|
14
README.md
14
README.md
|
@ -1,5 +1,15 @@
|
|||
# favicon-scraper
|
||||
|
||||
Scrapes favicons from websites.
|
||||
Scrapes favicons from websites. Does not particularly care for 100% optimal
|
||||
performance, it just needs to work.
|
||||
|
||||
Does not particularly care for 100% optimal performance, it just needs to work
|
||||
To get started, try the `scrape` function:
|
||||
|
||||
```rust
|
||||
use favicon_scraper::{scrape, Icon};
|
||||
|
||||
let icons: Vec<Icon> = scrape("https://google.com").await.unwrap();
|
||||
|
||||
// Should find something like "https://www.google.com/favicon.ico"
|
||||
println!("Google's icon can be found at {}", icons[0].url);
|
||||
```
|
||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -12,7 +12,7 @@ pub mod manifest;
|
|||
pub use error::Error;
|
||||
use futures::future::{join, join_all};
|
||||
use html::HTML;
|
||||
use icon::{Icon, IconKind};
|
||||
pub use icon::{Icon, IconKind};
|
||||
use manifest::scan_manifest;
|
||||
use reqwest::{Client, IntoUrl};
|
||||
use url::Url;
|
||||
|
@ -92,4 +92,14 @@ mod tests {
|
|||
println!("Kind of icon: {:?}\n", icon.kind);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_readme_example() {
|
||||
use crate::{scrape, Icon};
|
||||
|
||||
let icons: Vec<Icon> = scrape("https://google.com").await.unwrap();
|
||||
|
||||
// Should find something like "https://www.google.com/favicon.ico"
|
||||
println!("Google's icon can be found at {}", icons[0].url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,14 @@ struct ManifestIcon {
|
|||
|
||||
/// Scans a Web App Manifest for icons.
|
||||
pub async fn scan_manifest(client: &Client, url: impl IntoUrl) -> Result<Vec<Icon>, Error> {
|
||||
let manifest: Manifest = client.get(url).send().await?.json().await?;
|
||||
let url = url.into_url()?;
|
||||
let manifest: Manifest = client.get(url.clone()).send().await?.json().await?;
|
||||
Ok(join_all(
|
||||
manifest
|
||||
.icons
|
||||
.into_iter()
|
||||
.map(|i| Icon::from_url(client, i.src, IconKind::LinkedInManifest)),
|
||||
.filter_map(|i| url.join(&i.src).ok())
|
||||
.map(|u| Icon::from_url(client, u, IconKind::LinkedInManifest)),
|
||||
)
|
||||
.await
|
||||
.into_iter()
|
||||
|
|
Loading…
Add table
Reference in a new issue