pub struct StreamingHtmlParser { /* private fields */ }Expand description
Streaming HTML parser that processes content incrementally.
Buffers HTML chunks as they arrive and parses when a complete document is detected. This is useful for processing HTML from streaming sources like HTTP responses.
§Examples
use crawlkit_engine::parser::StreamingHtmlParser;
let mut parser = StreamingHtmlParser::new();
parser.feed("<!DOCTYPE html><html><head><title>Test</title></head>");
parser.feed("<body><h1>Hello</h1></body></html>");
assert!(parser.has_complete_document());
let page = parser.parse().unwrap();
assert_eq!(page.meta.title.as_deref(), Some("Test"));Implementations§
Source§impl StreamingHtmlParser
impl StreamingHtmlParser
Sourcepub fn feed(&mut self, chunk: &str)
pub fn feed(&mut self, chunk: &str)
Feed a chunk of HTML content into the parser.
The chunk is appended to the internal buffer for later parsing.
Sourcepub fn has_complete_document(&self) -> bool
pub fn has_complete_document(&self) -> bool
Check if the accumulated content contains a complete HTML document.
Returns true if the buffer contains </html> or </body> tags,
indicating the document is likely complete.
Sourcepub fn parse(&mut self) -> Result<ParsedPage, ParseError>
pub fn parse(&mut self) -> Result<ParsedPage, ParseError>
Parse the accumulated HTML content.
Delegates to HtmlParser::parse with a blank URL.
Returns a ParsedPage containing all extracted SEO data.
§Errors
Returns ParseError if parsing fails (currently never happens).
Sourcepub fn buffer_size(&self) -> usize
pub fn buffer_size(&self) -> usize
Get the current buffer size in bytes.
Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Consume the parser and return the buffered content.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StreamingHtmlParser
impl RefUnwindSafe for StreamingHtmlParser
impl Send for StreamingHtmlParser
impl Sync for StreamingHtmlParser
impl Unpin for StreamingHtmlParser
impl UnsafeUnpin for StreamingHtmlParser
impl UnwindSafe for StreamingHtmlParser
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more