pub struct HtmlParser { /* private fields */ }Expand description
Implementations§
Source§impl HtmlParser
impl HtmlParser
Sourcepub fn with_config(config: ParserConfig) -> Self
pub fn with_config(config: ParserConfig) -> Self
使用自定义配置创建解析器。
Sourcepub fn with_base_url(url: Url) -> Self
pub fn with_base_url(url: Url) -> Self
使用指定的基础 URL 创建解析器。
Sourcepub fn set_base_url(&mut self, url: Url)
pub fn set_base_url(&mut self, url: Url)
设置基础 URL,用于解析相对链接和图片地址。
Sourcepub fn config(&self) -> &ParserConfig
pub fn config(&self) -> &ParserConfig
获取当前配置的引用。
Sourcepub fn config_mut(&mut self) -> &mut ParserConfig
pub fn config_mut(&mut self) -> &mut ParserConfig
获取当前配置的可变引用。
Sourcepub fn parse(&self, html: &str) -> ParserResult<ParsedContent>
pub fn parse(&self, html: &str) -> ParserResult<ParsedContent>
解析完整的 HTML 文档,返回结构化内容。
自动计算解析统计信息,并根据配置决定提取哪些内容类型。
Sourcepub fn parse_fragment(&self, html: &str) -> ParserResult<ParsedContent>
pub fn parse_fragment(&self, html: &str) -> ParserResult<ParsedContent>
解析 HTML 片段(不包含 <html>/<body> 包装)。
适用于解析页面中的局部 HTML 内容。
Sourcepub fn extract_metadata(&self, html: &str) -> ParserResult<PageMetadata>
pub fn extract_metadata(&self, html: &str) -> ParserResult<PageMetadata>
提取页面元数据(标题、描述、OG、Twitter Card、结构化数据等)。
Sourcepub fn extract_text(&self, html: &str) -> ParserResult<TextContent>
pub fn extract_text(&self, html: &str) -> ParserResult<TextContent>
提取页面文本内容,含清洗、可读性评分。
Sourcepub fn extract_headings(&self, html: &str) -> Vec<Heading>
pub fn extract_headings(&self, html: &str) -> Vec<Heading>
提取所有标题(h1 - h6)。
Sourcepub fn extract_links(&self, html: &str) -> ParserResult<Vec<Link>>
pub fn extract_links(&self, html: &str) -> ParserResult<Vec<Link>>
提取所有链接。
Sourcepub fn extract_images(&self, html: &str) -> Vec<Image>
pub fn extract_images(&self, html: &str) -> Vec<Image>
提取所有图片,自动解析相对地址为绝对地址。
Sourcepub fn extract_lists(&self, html: &str) -> Vec<ListContent>
pub fn extract_lists(&self, html: &str) -> Vec<ListContent>
提取所有列表(有序、无序、定义列表)。
Sourcepub fn extract_tables(&self, html: &str) -> Vec<TableContent>
pub fn extract_tables(&self, html: &str) -> Vec<TableContent>
提取所有表格。
Sourcepub fn extract_code_blocks(&self, html: &str) -> Vec<CodeBlock>
pub fn extract_code_blocks(&self, html: &str) -> Vec<CodeBlock>
提取所有代码块。
Sourcepub fn extract_quotes(&self, html: &str) -> Vec<Quote>
pub fn extract_quotes(&self, html: &str) -> Vec<Quote>
提取所有引用(blockquote)。
Sourcepub fn extract_structured_data(&self, html: &str) -> Vec<StructuredData>
pub fn extract_structured_data(&self, html: &str) -> Vec<StructuredData>
提取所有结构化数据(JSON-LD + Microdata)。
Sourcepub fn resolve_url(&self, href: &str) -> Option<String>
pub fn resolve_url(&self, href: &str) -> Option<String>
将相对路径或协议相对 URL 解析为绝对 URL。
需要解析器已配置 base_url,否则返回 None。
Sourcepub fn has_base_url(&self) -> bool
pub fn has_base_url(&self) -> bool
检查是否已配置基础 URL。
Trait Implementations§
Source§impl Clone for HtmlParser
impl Clone for HtmlParser
Source§fn clone(&self) -> HtmlParser
fn clone(&self) -> HtmlParser
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HtmlParser
impl Debug for HtmlParser
Auto Trait Implementations§
impl Freeze for HtmlParser
impl RefUnwindSafe for HtmlParser
impl Send for HtmlParser
impl Sync for HtmlParser
impl Unpin for HtmlParser
impl UnsafeUnpin for HtmlParser
impl UnwindSafe for HtmlParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more