#web-scraping #full-text #readability #article #scrape

article_scraper

从网络上抓取文章内容。由 fivefilters 全文订阅配置和 mozilla 可读性提供支持。

11 个稳定版本

2.1.0 2024 年 3 月 24 日
2.0.0 2023 年 6 月 23 日
2.0.0-alpha.02023 年 4 月 23 日
1.1.7 2021 年 1 月 21 日
1.0.0 2020 年 4 月 28 日

179 in 网页编程

Download history 73/week @ 2024-04-20 77/week @ 2024-04-27 51/week @ 2024-05-04 73/week @ 2024-05-11 92/week @ 2024-05-18 93/week @ 2024-05-25 165/week @ 2024-06-01 66/week @ 2024-06-08 73/week @ 2024-06-15 33/week @ 2024-06-22 40/week @ 2024-06-29 55/week @ 2024-07-06 15/week @ 2024-07-13 31/week @ 2024-07-20 44/week @ 2024-07-27 19/week @ 2024-08-03

117 个月下载量
2 crates 中使用

GPL-3.0-or-later

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