class Nokogiri::HTML4::SAX::Parser

💡 This class is an alias for Nokogiri::HTML4::SAX::Parser as of v1.12.0.

This parser is a SAX style parser that reads its input as it deems necessary. The parser takes a Nokogiri::XML::SAX::Document, an optional encoding, then given an HTML input, sends messages to the Nokogiri::XML::SAX::Document.

âš  This is an HTML4 parser and so may not support some HTML5 features and behaviors.

Here is a basic usage example:

class MyHandler < Nokogiri::XML::SAX::Document
  def start_element name, attributes = []
    puts "found a #{name}"
  end
end

parser = Nokogiri::HTML4::SAX::Parser.new(MyHandler.new)

# Hand an IO object to the parser, which will read the HTML from the IO.
File.open(path_to_html) do |f|
  parser.parse(f)
end

For more information on SAX parsers, see Nokogiri::XML::SAX or the parent class Nokogiri::XML::SAX::Parser.

Also see Nokogiri::XML::SAX::Document for the available events.