Sha256: 4a3f7a1ad28c0adbbfe0d9e3a8c8203f7066f27d670c2f25d0e9ddc4e56eaefb
Contents?: true
Size: 1.14 KB
Versions: 3
Compression:
Stored size: 1.14 KB
Contents
require 'web/htmltools/xmltree' require 'mechanize/rexml' class WWW::Mechanize::REXMLPage < WWW::Mechanize::Page def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil) super(uri, response, body, code) @watch_for_set = {} @mech = mech yield self if block_given? raise Mechanize::ContentTypeError.new(response['content-type']) unless content_type() =~ /^text\/html/ # construct parser and feed with HTML parser = HTMLTree::XMLParser.new begin parser.feed(@body) rescue => ex if ex.message =~ /attempted adding second root element to document/ and # Put the whole document inside a single root element, which I # simply name <root>, just to make the parser happy. It's no #longer valid HTML, but without a single root element, it's not # valid HTML as well. # TODO: leave a possible doctype definition outside this element. parser = HTMLTree::XMLParser.new parser.feed("<root>" + @body + "</root>") else raise end end @root = parser.document parse_html if body && response end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mechanize-0.6.1 | lib/mechanize/parsers/rexml_page.rb |
mechanize-0.6.2 | lib/mechanize/parsers/rexml_page.rb |
mechanize-0.6.3 | lib/mechanize/parsers/rexml_page.rb |