Xavi Caballé
2010-Jun-10 20:28 UTC
[Mechanize-users] submit button param is duplicated when a form is submitted a second time
Hello, Below I''ve pasted a simple example to reproduce what I say in the subject. I wonder... Is it a bug? Is there any workaround? Thanks! require ''rubygems'' require ''mechanize'' agent = Mechanize.new page = agent.get(''http://google.com/'') google_form = page.form(''f'') google_form.q = ''ruby mechanize'' page = agent.submit(google_form, google_form.buttons.last) pp google_form.request_data page = agent.submit(google_form, google_form.buttons.last) pp google_form.request_data
Aaron Starr
2010-Jun-11 00:24 UTC
[Mechanize-users] submit button param is duplicated when a form is submitted a second time
I think it''s working as expected. You probably want to do this: require ''rubygems'' require ''mechanize'' agent = Mechanize.new page = agent.get(''http://google.com/'') google_form = page.form(''f'') google_form.q = ''ruby mechanize'' page = agent.submit(google_form, google_form.buttons.last) + google_form = page.form(''f'') pp google_form.request_data page = agent.submit(google_form, google_form.buttons.last) + google_form = page.form(''f'') pp google_form.request_data I.e., use the new form from the new page, rather than continuing to use the old form that you added the button to. Or, if you really want to use the old form, for some reason, I think you could just do this: require ''rubygems'' require ''mechanize'' agent = Mechanize.new page = agent.get(''http://google.com/'') google_form = page.form(''f'') google_form.q = ''ruby mechanize'' page = agent.submit(google_form, google_form.buttons.last) pp google_form.request_data - page = agent.submit(google_form, google_form.buttons.last) + page = agent.submit(google_form) pp google_form.request_data On Thu, Jun 10, 2010 at 1:28 PM, Xavi Caball? <xavi.caballe at gmail.com>wrote:> Hello, > > Below I''ve pasted a simple example to reproduce what I say in the > subject. I wonder... > Is it a bug? Is there any workaround? > > Thanks! > > > require ''rubygems'' > require ''mechanize'' > > agent = Mechanize.new > page = agent.get(''http://google.com/'') > google_form = page.form(''f'') > google_form.q = ''ruby mechanize'' > page = agent.submit(google_form, google_form.buttons.last) > pp google_form.request_data > page = agent.submit(google_form, google_form.buttons.last) > pp google_form.request_data > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100610/a234b39b/attachment.html>
Xavi Caballé
2010-Jun-11 12:30 UTC
[Mechanize-users] submit button param is duplicated when a form is submitted a second time
I really want to use the old form, but submit it with another button, so what you propose doesn''t work for what I want (as it submits the form with the same button I used the first time). I''ve implemented a reset_clicked_buttons to work around this, but I think it should be supported, otherwise how do you "mechanize" a browsing sequence like... - user visits google.com - clicks on "Google Search" - goes back - now clicks on "I''m Feeling Lucky" (browsers only send this button, not the button that was clicked before, but Mechanize would send both) Thanks! On Fri, Jun 11, 2010 at 2:24 AM, Aaron Starr <astarr at wiredquote.com> wrote:> > I think it''s working as expected. You probably want to do this: > ?? require ''rubygems'' > ?? require ''mechanize'' > > ?? agent = Mechanize.new > ?? page = agent.get(''http://google.com/'') > ?? google_form = page.form(''f'') > ?? google_form.q = ''ruby mechanize'' > ?? page = agent.submit(google_form, google_form.buttons.last) > + google_form = page.form(''f'') > ?? pp google_form.request_data > ?? page = agent.submit(google_form, google_form.buttons.last) > + google_form = page.form(''f'') > ?? pp google_form.request_data > > I.e., use the new form from the new page, rather than continuing to use the > old form that you added the button to. Or, if you really want to use the old > form, for some reason, I think you could just do this: > ?? require ''rubygems'' > ?? require ''mechanize'' > > ?? agent = Mechanize.new > ?? page = agent.get(''http://google.com/'') > ?? google_form = page.form(''f'') > ?? google_form.q = ''ruby mechanize'' > ?? page = agent.submit(google_form, google_form.buttons.last) > ?? pp google_form.request_data > - ?page = agent.submit(google_form, google_form.buttons.last) > + page = agent.submit(google_form) > ?? pp google_form.request_data > > > > On Thu, Jun 10, 2010 at 1:28 PM, Xavi Caball? <xavi.caballe at gmail.com> > wrote: >> >> Hello, >> >> Below I''ve pasted a simple example to reproduce what I say in the >> subject. I wonder... >> Is it a bug? Is there any workaround? >> >> Thanks! >> >> >> require ''rubygems'' >> require ''mechanize'' >> >> agent = Mechanize.new >> page = agent.get(''http://google.com/'') >> google_form = page.form(''f'') >> google_form.q = ''ruby mechanize'' >> page = agent.submit(google_form, google_form.buttons.last) >> pp google_form.request_data >> page = agent.submit(google_form, google_form.buttons.last) >> pp google_form.request_data >> _______________________________________________ >> Mechanize-users mailing list >> Mechanize-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mechanize-users > > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users >