11 个稳定版本
2.1.0 | 2024 年 3 月 24 日 |
---|---|
2.0.0 | 2023 年 6 月 23 日 |
2.0.0-alpha.0 | 2023 年 4 月 23 日 |
1.1.7 | 2021 年 1 月 21 日 |
1.0.0 | 2020 年 4 月 28 日 |
179 in 网页编程
117 个月下载量
在 2 crates 中使用
415KB
5K SLoC
article scraper
article_scraper
crate 提供了一种简单的方法从网络上提取有意义的内容。它包含两种定位所需内容的方式:
1. 基于 Full-Text RSS 的 Rust 实现
这利用了网站特定的提取规则。其优点是快速且准确的结果。然而,缺点是需要随着网站的变化更新配置,并且每个网站都需要新的提取规则。
提取规则和信息的相关中央仓库可以在这里找到:ftr-site-config。请考虑为此贡献新的规则或更新。
article_scraper
将所有规则嵌入到 ftr-site-config 仓库中,以便于使用。自定义和更新的规则可以从 user_configs
路径加载。
2. Mozilla Readability
如果基于 ftr-config 的提取失败,将使用 mozilla Readability 算法作为后备。这个重实现试图尽可能地模仿原始算法。
示例
use article_scraper::ArticleScraper;
use url::Url;
use reqwest::Client;
let scraper = ArticleScraper::new(None);
let url = Url::parse("https://www.nytimes.com/interactive/2023/04/21/science/parrots-video-chat-facetime.html");
let client = Client::new();
let article = scraper.parse(&url, false, &client, None).await.unwrap();
CLI
此 crate 的各种功能可以通过 article_scraper_cli
使用。
Usage: article_scraper_cli [OPTIONS] <COMMAND>
Commands:
all Use the complete pipeline
readability Only use the Readability parser
ftr Only use (a subset of) the Ftr parser
help Print this message or the help of the given subcommand(s)
Options:
-d, --debug Turn debug logging on
-o, --output <FILE> Destination of resulting HTML file
-h, --help Print help
-V, --version Print version
依赖关系
~17–31MB
~563K SLoC