Ben G
Ben G

Reputation: 26771

Parsing malformed HTML with Mechanize (Ruby)

I'd like to process an HTTP response that has a lot of HTML in it but is not itself a valid HTML file.

I'm aware that I could use Nokogiri as follows: page = Nokogiri::HTML.parse(page.body), however, I'd like to have access to the Mechanize methods like Mechanize::Page.search. Is there any way to work with this HTML as a Mechanize::Page, or through some other Mechanize class?

Upvotes: 0

Views: 263

Answers (1)

Ben G
Ben G

Reputation: 26771

Actually, looks like I've found the answer to my own question:

 page  = Mechanize::Page.new(URI.parse('http://example.com'), {'content-type'=>'text/html'},(page.body), 200, agent)

Upvotes: 2

Related Questions