crawlkit_parser/lib.rs
1//! # crawlkit-parser
2//!
3//! HTML 解析与内容提取模块。
4//! 基于 `scraper`(html5ever)和 `dom_smoothie`(Readability 模式)实现。
5//!
6//! ## 模块
7//!
8//! - `html`:原有基础工具(链接提取、文章提取、可读性)
9//! - `types`:共享类型定义
10//! - `selector`:预编译 CSS 选择器
11//! - `metadata`:页面元数据(OG/Twitter/JSON-LD/Robots)
12//! - `text`:正文提取、文本规范化、可读性评分、语言检测
13//! - `links`:链接提取、URL 规范化、站内外分类
14//! - `content`:结构化内容(标题/列表/表格/代码/引用)
15//! - `parser`:HtmlParser 统一入口
16//! - `forms`:表单检测与分类
17//! - `pagination`:翻页检测
18//! - `contact`:联系方式提取
19//! - `feeds`:Feed/Sitemap 检测
20//! - `rules`:URL 正则规则引擎(UrlRule)
21//! - `extractor`:基于 DOM 聚类 + 打分的文章链接提取器
22//! - `fingerprint`:内容指纹与 AMP 检测
23
24pub mod html;
25pub mod types;
26pub mod selector;
27pub mod metadata;
28pub mod text;
29pub mod links;
30pub mod content;
31pub mod parser;
32pub mod forms;
33pub mod pagination;
34pub mod contact;
35pub mod feeds;
36pub mod fingerprint;
37pub mod rules;
38pub mod extractor;
39
40// 向后兼容的模块别名
41pub mod selectors;
42
43// ============================================================================
44// 类型重导出
45// ============================================================================
46
47pub use types::{
48 ParserError, ParserResult,
49 TextContent,
50 Heading,
51 Link, LinkRel, LinkType,
52 Image, ImageLoading,
53 ListContent, ListType, ListItem,
54 TableContent, TableRow, TableCell,
55 CodeBlock,
56 Quote,
57 PageMetadata, OpenGraph, TwitterCard, RobotsMeta, AlternateLink,
58 StructuredData, StructuredDataFormat,
59 ParsedContent, ParseStats,
60 ParserConfig,
61 normalize_whitespace, clean_text, truncate_text,
62};
63
64// ============================================================================
65// 选择器工具
66// ============================================================================
67
68pub use selector::{
69 SELECTORS, CachedSelectors,
70 get_or_create_selector, parse_selector, try_parse_selector,
71 heading_selector,
72 CONTENT_SELECTORS, BOILERPLATE_SELECTORS,
73 attr_selector, class_selector, id_selector,
74 meta_name_selector, meta_property_selector, link_rel_selector,
75};
76
77// ============================================================================
78// 元数据提取
79// ============================================================================
80
81pub use metadata::{
82 extract_metadata,
83 extract_title, extract_charset, extract_language,
84 extract_meta_content, extract_keywords,
85 extract_canonical, extract_favicon,
86 extract_robots,
87 extract_opengraph, extract_twitter_card,
88 extract_alternates,
89 extract_structured_data, extract_json_ld, extract_microdata,
90};
91
92// ============================================================================
93// 文本处理
94// ============================================================================
95
96pub use text::{
97 extract_text as extract_text_content,
98 normalize_text, strip_html_tags,
99 count_words, count_sentences,
100 flesch_reading_ease, flesch_kincaid_grade,
101 detect_language,
102 is_inline_element,
103};
104
105// ============================================================================
106// HTML 基础工具(向后兼容)
107// ============================================================================
108
109pub use html::{
110 Article, LinkSelectorType,
111 extract_absolute_links, extract_article, extract_attributes,
112 extract_content, extract_content_by_selector,
113 extract_links, extract_links_by_selector,
114 extract_links_by_xpath, extract_readable_content,
115 extract_texts, resolve_url, try_extract_links,
116 sanitize_for_xpath,
117};
118
119// ============================================================================
120// 内容提取(结构化)
121// ============================================================================
122
123pub use content::{
124 extract_headings, get_main_heading, build_outline,
125 extract_paragraphs,
126 extract_lists, extract_tables,
127 extract_code_blocks, extract_quotes,
128};
129
130// ============================================================================
131// 链接分析
132// ============================================================================
133
134pub use links::{
135 LinkStats,
136 normalize_url,
137 parse_rel_attribute, is_nofollow, is_sponsored, is_ugc,
138 filter_internal_links, filter_external_links, filter_followable_links,
139 get_external_domains, calculate_link_stats,
140};
141
142// ============================================================================
143// HtmlParser 入口
144// ============================================================================
145
146pub use parser::{
147 HtmlParser,
148 parse, parse_with_url,
149 get_metadata, get_text, get_links,
150};
151
152// ============================================================================
153// 表单提取
154// ============================================================================
155
156pub use forms::{
157 Form, FormField, FormType, FieldType, FormMethod, SelectOption,
158 extract_forms,
159 has_forms, has_login_form, has_search_form,
160 get_login_forms, get_search_forms, get_contact_forms,
161};
162
163// ============================================================================
164// 翻页检测
165// ============================================================================
166
167pub use pagination::{
168 Pagination, PageUrl, PaginationType,
169 extract_pagination, has_pagination,
170 get_next_page, get_prev_page,
171};
172
173// ============================================================================
174// 联系方式提取
175// ============================================================================
176
177pub use contact::{
178 ContactInfo, Email, EmailSource, Phone, PhoneType,
179 Address, Coordinates, SocialLink, SocialPlatform,
180 extract_contact_info, extract_emails, extract_phones,
181 extract_addresses, extract_social_links,
182 has_contact_info, get_emails, get_phones, get_social_links,
183};
184
185// ============================================================================
186// Feed / Sitemap 检测
187// ============================================================================
188
189pub use feeds::{
190 FeedInfo, Feed, FeedType, Sitemap, SitemapType, SitemapSource,
191 extract_feed_info, has_feeds, get_rss_feed, get_atom_feed, get_feed, get_sitemap,
192};
193
194// ============================================================================
195// 内容指纹与 AMP
196// ============================================================================
197
198pub use fingerprint::{
199 ContentFingerprint, AmpInfo, CacheHints,
200 generate_fingerprint, fingerprint_document,
201 extract_amp_info, extract_cache_hints,
202 has_content_changed, content_similarity, is_amp_page, get_amp_url, quick_hash,
203};
204
205// ============================================================================
206// 第三方重导出
207// ============================================================================
208
209// ============================================================================
210// URL 规则引擎
211// ============================================================================
212
213pub use rules::UrlRule;
214
215// ============================================================================
216// 文章链接提取
217// ============================================================================
218
219pub use extractor::{ExtractedLink, ExtractorConfig, LinkExtractor};
220
221/// 重新导出 scraper 供上层 crate 构建 Element
222pub use scraper;
223
224/// 重新导出 skyscraper 供上层 crate 实现 XPath 元素回调
225pub use skyscraper;