Parsing HTML with Ruby Mechanize

I am new to using mechanization and even Ruby in general. I use it to navigate a site with poorly distorted HTML. In particular, I have a page with checkboxes outside the form (despite this, the server handles requests well).

I would like to check these fields and click the submit button (also outside the form). However, I canโ€™t use Form.checkbox_withit because I donโ€™t have an object Form, I only have it Page. I can check the box on the page with page.search("//input[@name='silly-checkbox']"), but as far as I understand, I can not check it after (because Nokogiri is used only for cleaning and does not track the status). Please let me know if this is not true.

Bottom line . How can I get an object Mechanize::Form::Checkboxwhen my checkbox is not in form?

+3
source share
2 answers

You can manually load the remote page with a simple old Nokogiri, then fix the markup (i.e. find the checkboxes outside the forms and wrap them) and build the Mechanize classes yourself from the fixed HTML code.

0
source

You can change your shape by deleting and changing new fields.

form.add_field!('gender', 'male')

rdoc is here

0
source

All Articles