Robert Poor
2011-May-03 02:37 UTC
[Mechanize-users] parsing and submitting a form from a page with missing content type?
[cross posted on Nokogiri and Mechanize lists] I have a page that is missing a valid content type, but it appears to contain (mostly?) well formed HTML. My goal is to agent.click() on a button in the form, but I don''t know the best way to get there. The first lines read: <html> <head> <meta name="generator" content="HTML Tidy, see www.w3.org"> ... When I coerce Mechanize to use Mechanize::Page as the parser via: @agent.pluggable_parser.default = Mechanize::Page I get a Mechanize::ContentTypeError (okay, so maybe it isn''t so well formed). But Nokogiri is able to parse it without error. So: what''s the best way (or easiest way) to submit the form from the loaded page? I see two options: * xpath to the appropriate form using Nokogiri and then (somehow) pass the form to Mechanize to submit. But I''m not sure of the syntax for that. * write my own pluggable parser that somehow knows how to deal with the page. I''m even foggier on how that would work. Suggestions or examples are welcome...