Got a form, hitting a button with Mechanize. Thus far have been going through login steps quite nicely so I know my Mechanize basics are up to snuff. Then I get: URI::InvalidURIError: bad URI(is not URI?): CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 from /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in `split'' from /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in `parse'' from /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in `parse'' from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in `rescue in resolve'' from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in `resolve'' from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in `fetch'' from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in `post_form'' from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in `submit'' from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in `submit'' from (irb):69 from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'' from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'' from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'' from script/rails:6:in `require'' from script/rails:6:in `<main>''>From the googling I''ve done, seems to be related to an invalid character inthe re-direct, but really I have no idea... Any way of ignoring these weird characters and continuing? Anyway of fixing this? Best, Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20130225/2f1ca9e8/attachment-0001.html>
Hi Kevin, It looks like the "action" attribute of your form contains something along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". The semicolon in here is not strictly a valid character in an URL. Try replacing it with %3B. form = page.at( ...select the form with a selector... ) action = form.attr(''action'') action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') form.attr(''action'', action) # then submit the form as usual (You can''t do form.submit because this form object we have here is a nokogiri node. You need to go through mechanize to submit the form.) Godfrey? ? Sent from Mailbox for iPhone On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann <kevin at proofimaging.com> wrote:> Got a form, hitting a button with Mechanize. Thus far have been going > through login steps quite nicely so I know my Mechanize basics are up to > snuff. > Then I get: > URI::InvalidURIError: bad URI(is not URI?): > CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 > from > /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in > `split'' > from > /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in > `parse'' > from > /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in > `parse'' > from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in > `rescue in resolve'' > from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in > `resolve'' > from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in > `fetch'' > from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in > `post_form'' > from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in > `submit'' > from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in > `submit'' > from (irb):69 > from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in > `start'' > from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in > `start'' > from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in > `<top (required)>'' > from script/rails:6:in `require'' > from script/rails:6:in `<main>'' >>From the googling I''ve done, seems to be related to an invalid character in > the re-direct, but really I have no idea... > Any way of ignoring these weird characters and continuing? Anyway of fixing > this? > Best, > Kevin-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20130225/3927e41a/attachment.html>
Hi Godfrey, Thanks for your help. Really working hard to figure this out. I ran into a road block that is my inexperience with nokogiri and mech. When I try to grab the action (action = form.attr(''action'')), I get undefined method... Here is what I''m doing exactly: agent = Mechanize.new agent.user_agent_alias = ''Mac Safari'' page = agent.get(''https://somesite.jsp'') form = agent.page.forms.first action = form.attr(''action'') and undefined method... I tried seeing if I could grab the action various ways to no avail. My other question is, assuming I do this successfuly, I would normally use "form.submit" but you''re saying this won''t work? What should I try? Thanks again for your help!! Kevin On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan <godfreykfc at gmail.com> wrote:> Hi Kevin, > > It looks like the "action" attribute of your form contains something along > the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". The > semicolon in here is not strictly a valid character in an URL. Try > replacing it with %3B. > > form = page.at( ...select the form with a selector... ) > > action = form.attr(''action'') > > action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') > > form.attr(''action'', action) > > # then submit the form as usual (You can''t do form.submit because this > form object we have here is a nokogiri node. You need to go through > mechanize to submit the form.) > > Godfrey > ? > Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone > > > On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann <kevin at proofimaging.com>wrote: > >> Got a form, hitting a button with Mechanize. Thus far have been going >> through login steps quite nicely so I know my Mechanize basics are up to >> snuff. >> >> Then I get: >> >> URI::InvalidURIError: bad URI(is not URI?): >> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >> from >> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in >> `split'' >> from >> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in >> `parse'' >> from >> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in >> `parse'' >> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in >> `rescue in resolve'' >> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in >> `resolve'' >> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in >> `fetch'' >> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in >> `post_form'' >> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in >> `submit'' >> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in >> `submit'' >> from (irb):69 >> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in >> `start'' >> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in >> `start'' >> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in >> `<top (required)>'' >> from script/rails:6:in `require'' >> from script/rails:6:in `<main>'' >> >> From the googling I''ve done, seems to be related to an invalid character >> in the re-direct, but really I have no idea... >> >> Any way of ignoring these weird characters and continuing? Anyway of >> fixing this? >> >> Best, >> Kevin >> > > > _______________________________________________ > 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/20130225/b10b4cbe/attachment.html>
actually, this grabbed it: action = form.action and your gsub worked a charm. Just need to get this to submit... Because you''re right form.submit didn''t work... I tried what you gave me: action = form.attr(''action'') But undefined meth again on attr... On Mon, Feb 25, 2013 at 10:29 PM, Kevin Kornemann <kevin at proofimaging.com>wrote:> Hi Godfrey, > > Thanks for your help. Really working hard to figure this out. I ran into a > road block that is my inexperience with nokogiri and mech. > > When I try to grab the action (action = form.attr(''action'')), I get > undefined method... Here is what I''m doing exactly: > > agent = Mechanize.new > agent.user_agent_alias = ''Mac Safari'' > page = agent.get(''https://somesite.jsp'') > > form = agent.page.forms.first > action = form.attr(''action'') > > and undefined method... > I tried seeing if I could grab the action various ways to no avail. > > My other question is, assuming I do this successfuly, I would normally use > "form.submit" but you''re saying this won''t work? What should I try? > > Thanks again for your help!! > Kevin > > > On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: > >> Hi Kevin, >> >> It looks like the "action" attribute of your form contains something >> along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". >> The semicolon in here is not strictly a valid character in an URL. Try >> replacing it with %3B. >> >> form = page.at( ...select the form with a selector... ) >> >> action = form.attr(''action'') >> >> action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') >> >> form.attr(''action'', action) >> >> # then submit the form as usual (You can''t do form.submit because this >> form object we have here is a nokogiri node. You need to go through >> mechanize to submit the form.) >> >> Godfrey >> ? >> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >> >> >> On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann <kevin at proofimaging.com>wrote: >> >>> Got a form, hitting a button with Mechanize. Thus far have been going >>> through login steps quite nicely so I know my Mechanize basics are up to >>> snuff. >>> >>> Then I get: >>> >>> URI::InvalidURIError: bad URI(is not URI?): >>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>> from >>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in >>> `split'' >>> from >>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in >>> `parse'' >>> from >>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in >>> `parse'' >>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in >>> `rescue in resolve'' >>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in >>> `resolve'' >>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in >>> `fetch'' >>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in >>> `post_form'' >>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in >>> `submit'' >>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in >>> `submit'' >>> from (irb):69 >>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in >>> `start'' >>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in >>> `start'' >>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in >>> `<top (required)>'' >>> from script/rails:6:in `require'' >>> from script/rails:6:in `<main>'' >>> >>> From the googling I''ve done, seems to be related to an invalid character >>> in the re-direct, but really I have no idea... >>> >>> Any way of ignoring these weird characters and continuing? Anyway of >>> fixing this? >>> >>> Best, >>> Kevin >>> >> >> >> _______________________________________________ >> 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/20130225/14314871/attachment-0001.html>
sorry meant I tried: form.attr(''action'', action) to no avail...? On Mon, Feb 25, 2013 at 10:35 PM, Kevin Kornemann <kevin at proofimaging.com>wrote:> actually, this grabbed it: > > action = form.action > > and your gsub worked a charm. > > Just need to get this to submit... Because you''re right form.submit didn''t > work... I tried what you gave me: > > action = form.attr(''action'') > > But undefined meth again on attr... > > On Mon, Feb 25, 2013 at 10:29 PM, Kevin Kornemann <kevin at proofimaging.com>wrote: > >> Hi Godfrey, >> >> Thanks for your help. Really working hard to figure this out. I ran into >> a road block that is my inexperience with nokogiri and mech. >> >> When I try to grab the action (action = form.attr(''action'')), I get >> undefined method... Here is what I''m doing exactly: >> >> agent = Mechanize.new >> agent.user_agent_alias = ''Mac Safari'' >> page = agent.get(''https://somesite.jsp'') >> >> form = agent.page.forms.first >> action = form.attr(''action'') >> >> and undefined method... >> I tried seeing if I could grab the action various ways to no avail. >> >> My other question is, assuming I do this successfuly, I would normally >> use "form.submit" but you''re saying this won''t work? What should I try? >> >> Thanks again for your help!! >> Kevin >> >> >> On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: >> >>> Hi Kevin, >>> >>> It looks like the "action" attribute of your form contains something >>> along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". >>> The semicolon in here is not strictly a valid character in an URL. Try >>> replacing it with %3B. >>> >>> form = page.at( ...select the form with a selector... ) >>> >>> action = form.attr(''action'') >>> >>> action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') >>> >>> form.attr(''action'', action) >>> >>> # then submit the form as usual (You can''t do form.submit because this >>> form object we have here is a nokogiri node. You need to go through >>> mechanize to submit the form.) >>> >>> Godfrey >>> ? >>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>> >>> >>> On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann <kevin at proofimaging.com >>> > wrote: >>> >>>> Got a form, hitting a button with Mechanize. Thus far have been going >>>> through login steps quite nicely so I know my Mechanize basics are up to >>>> snuff. >>>> >>>> Then I get: >>>> >>>> URI::InvalidURIError: bad URI(is not URI?): >>>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>>> from >>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in >>>> `split'' >>>> from >>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in >>>> `parse'' >>>> from >>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in >>>> `parse'' >>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in >>>> `rescue in resolve'' >>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in >>>> `resolve'' >>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in >>>> `fetch'' >>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in >>>> `post_form'' >>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in >>>> `submit'' >>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in >>>> `submit'' >>>> from (irb):69 >>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in >>>> `start'' >>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in >>>> `start'' >>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in >>>> `<top (required)>'' >>>> from script/rails:6:in `require'' >>>> from script/rails:6:in `<main>'' >>>> >>>> From the googling I''ve done, seems to be related to an invalid >>>> character in the re-direct, but really I have no idea... >>>> >>>> Any way of ignoring these weird characters and continuing? Anyway of >>>> fixing this? >>>> >>>> Best, >>>> Kevin >>>> >>> >>> >>> _______________________________________________ >>> 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/20130225/114152ac/attachment.html>
Hi Kevin, I?don''t currently have my computer with me to check the code?- so sorry?I can''t be more helpful. I might have made some of these methods up, so apply a good dose of common sense if things didn''t work as expected :) I believe this should do the trick: form = agent.current_page.forms.first form.action = form.action.gsub(...).gsub(...) form.submit Forget what I said earlier about the nokogiri stuff and form.submit won''t work etc. I wasn''t aware that you can change the form action from mechanize. If form.submit somehow?didn''t work, please post a trace. Godfrey ? Sent from Mailbox for iPhone On Mon, Feb 25, 2013 at 7:38 PM, Kevin Kornemann <kevin at proofimaging.com> wrote:> sorry meant I tried: > form.attr(''action'', action) > to no avail...? > On Mon, Feb 25, 2013 at 10:35 PM, Kevin Kornemann <kevin at proofimaging.com>wrote: >> actually, this grabbed it: >> >> action = form.action >> >> and your gsub worked a charm. >> >> Just need to get this to submit... Because you''re right form.submit didn''t >> work... I tried what you gave me: >> >> action = form.attr(''action'') >> >> But undefined meth again on attr... >> >> On Mon, Feb 25, 2013 at 10:29 PM, Kevin Kornemann <kevin at proofimaging.com>wrote: >> >>> Hi Godfrey, >>> >>> Thanks for your help. Really working hard to figure this out. I ran into >>> a road block that is my inexperience with nokogiri and mech. >>> >>> When I try to grab the action (action = form.attr(''action'')), I get >>> undefined method... Here is what I''m doing exactly: >>> >>> agent = Mechanize.new >>> agent.user_agent_alias = ''Mac Safari'' >>> page = agent.get(''https://somesite.jsp'') >>> >>> form = agent.page.forms.first >>> action = form.attr(''action'') >>> >>> and undefined method... >>> I tried seeing if I could grab the action various ways to no avail. >>> >>> My other question is, assuming I do this successfuly, I would normally >>> use "form.submit" but you''re saying this won''t work? What should I try? >>> >>> Thanks again for your help!! >>> Kevin >>> >>> >>> On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: >>> >>>> Hi Kevin, >>>> >>>> It looks like the "action" attribute of your form contains something >>>> along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". >>>> The semicolon in here is not strictly a valid character in an URL. Try >>>> replacing it with %3B. >>>> >>>> form = page.at( ...select the form with a selector... ) >>>> >>>> action = form.attr(''action'') >>>> >>>> action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') >>>> >>>> form.attr(''action'', action) >>>> >>>> # then submit the form as usual (You can''t do form.submit because this >>>> form object we have here is a nokogiri node. You need to go through >>>> mechanize to submit the form.) >>>> >>>> Godfrey >>>> ? >>>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>>> >>>> >>>> On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann <kevin at proofimaging.com >>>> > wrote: >>>> >>>>> Got a form, hitting a button with Mechanize. Thus far have been going >>>>> through login steps quite nicely so I know my Mechanize basics are up to >>>>> snuff. >>>>> >>>>> Then I get: >>>>> >>>>> URI::InvalidURIError: bad URI(is not URI?): >>>>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>>>> from >>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in >>>>> `split'' >>>>> from >>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in >>>>> `parse'' >>>>> from >>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in >>>>> `parse'' >>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in >>>>> `rescue in resolve'' >>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in >>>>> `resolve'' >>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in >>>>> `fetch'' >>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in >>>>> `post_form'' >>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in >>>>> `submit'' >>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in >>>>> `submit'' >>>>> from (irb):69 >>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in >>>>> `start'' >>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in >>>>> `start'' >>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in >>>>> `<top (required)>'' >>>>> from script/rails:6:in `require'' >>>>> from script/rails:6:in `<main>'' >>>>> >>>>> From the googling I''ve done, seems to be related to an invalid >>>>> character in the re-direct, but really I have no idea... >>>>> >>>>> Any way of ignoring these weird characters and continuing? Anyway of >>>>> fixing this? >>>>> >>>>> Best, >>>>> Kevin >>>>> >>>> >>>> >>>> _______________________________________________ >>>> 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/20130225/6a672922/attachment-0001.html>
Hi Godfrey, 1) Thanks again for your help, I really appreciate it. 2) yeah, so I can grab the action, gsub it nicely (I see the return). But when I ''form.submit'' it errors out on the original URI, as if the new version wasn''t changed at all... I''ll keep trying and let you know how I do. ENough for tonight. thanks, Kevin On Mon, Feb 25, 2013 at 10:50 PM, Godfrey Chan <godfreykfc at gmail.com> wrote:> Hi Kevin, > > I don''t currently have my computer with me to check the code - so sorry I > can''t be more helpful. I might have made some of these methods up, so apply > a good dose of common sense if things didn''t work as expected :) > > I believe this should do the trick: > > form = agent.current_page.forms.first > > form.action = form.action.gsub(...).gsub(...) > > form.submit > > Forget what I said earlier about the nokogiri stuff and form.submit won''t > work etc. I wasn''t aware that you can change the form action from mechanize. > > If form.submit somehow didn''t work, please post a trace. > > Godfrey > ? > Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone > > > On Mon, Feb 25, 2013 at 7:38 PM, Kevin Kornemann <kevin at proofimaging.com>wrote: > >> sorry meant I tried: >> >> form.attr(''action'', action) >> >> to no avail...? >> >> On Mon, Feb 25, 2013 at 10:35 PM, Kevin Kornemann <kevin at proofimaging.com >> > wrote: >> >>> actually, this grabbed it: >>> >>> action = form.action >>> >>> and your gsub worked a charm. >>> >>> Just need to get this to submit... Because you''re right form.submit >>> didn''t work... I tried what you gave me: >>> >>> action = form.attr(''action'') >>> >>> But undefined meth again on attr... >>> >>> On Mon, Feb 25, 2013 at 10:29 PM, Kevin Kornemann < >>> kevin at proofimaging.com> wrote: >>> >>>> Hi Godfrey, >>>> >>>> Thanks for your help. Really working hard to figure this out. I ran >>>> into a road block that is my inexperience with nokogiri and mech. >>>> >>>> When I try to grab the action (action = form.attr(''action'')), I get >>>> undefined method... Here is what I''m doing exactly: >>>> >>>> agent = Mechanize.new >>>> agent.user_agent_alias = ''Mac Safari'' >>>> page = agent.get(''https://somesite.jsp'') >>>> >>>> form = agent.page.forms.first >>>> action = form.attr(''action'') >>>> >>>> and undefined method... >>>> I tried seeing if I could grab the action various ways to no avail. >>>> >>>> My other question is, assuming I do this successfuly, I would normally >>>> use "form.submit" but you''re saying this won''t work? What should I try? >>>> >>>> Thanks again for your help!! >>>> Kevin >>>> >>>> >>>> On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: >>>> >>>>> Hi Kevin, >>>>> >>>>> It looks like the "action" attribute of your form contains something >>>>> along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". >>>>> The semicolon in here is not strictly a valid character in an URL. Try >>>>> replacing it with %3B. >>>>> >>>>> form = page.at( ...select the form with a selector... ) >>>>> >>>>> action = form.attr(''action'') >>>>> >>>>> action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') >>>>> >>>>> form.attr(''action'', action) >>>>> >>>>> # then submit the form as usual (You can''t do form.submit because this >>>>> form object we have here is a nokogiri node. You need to go through >>>>> mechanize to submit the form.) >>>>> >>>>> Godfrey >>>>> ? >>>>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>>>> >>>>> >>>>> On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann < >>>>> kevin at proofimaging.com> wrote: >>>>> >>>>>> Got a form, hitting a button with Mechanize. Thus far have been going >>>>>> through login steps quite nicely so I know my Mechanize basics are up to >>>>>> snuff. >>>>>> >>>>>> Then I get: >>>>>> >>>>>> URI::InvalidURIError: bad URI(is not URI?): >>>>>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>>>>> from >>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in >>>>>> `split'' >>>>>> from >>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in >>>>>> `parse'' >>>>>> from >>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in >>>>>> `parse'' >>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in >>>>>> `rescue in resolve'' >>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in >>>>>> `resolve'' >>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in >>>>>> `fetch'' >>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in >>>>>> `post_form'' >>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in >>>>>> `submit'' >>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in >>>>>> `submit'' >>>>>> from (irb):69 >>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in >>>>>> `start'' >>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in >>>>>> `start'' >>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in >>>>>> `<top (required)>'' >>>>>> from script/rails:6:in `require'' >>>>>> from script/rails:6:in `<main>'' >>>>>> >>>>>> From the googling I''ve done, seems to be related to an invalid >>>>>> character in the re-direct, but really I have no idea... >>>>>> >>>>>> Any way of ignoring these weird characters and continuing? Anyway of >>>>>> fixing this? >>>>>> >>>>>> Best, >>>>>> Kevin >>>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20130225/9a53db94/attachment.html>
Hi Kevin, I finally have access to my computer now, and it turns out the semi colon in the action is not the corrupt - the colon ("...:-1") was the issue. (Didn''t notice that before, I thought it was a line number or some sort of error code. That''s a *really* weird URI.)>> require ''mechanize'' >> agent = Mechanize.new >> page = agent.get ''http://formtest.dev/form_test.html'' >> form = page.forms.first >> form.submitURI::InvalidURIError: bad URI(is not URI?): CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1>> form.action = CGI.escape(form.action) >> form.submit # this should work nowIf your server fail to URL decode that for some odd reason and refuse to process that, you can try: form.action = ''./'' + form.action Hope it helps. Godfrey On Mon, Feb 25, 2013 at 8:06 PM, Kevin Kornemann <kevin at proofimaging.com>wrote:> Hi Godfrey, > > 1) Thanks again for your help, I really appreciate it. > 2) yeah, so I can grab the action, gsub it nicely (I see the return). But > when I ''form.submit'' it errors out on the original URI, as if the new > version wasn''t changed at all... > > I''ll keep trying and let you know how I do. ENough for tonight. > thanks, > Kevin > > > On Mon, Feb 25, 2013 at 10:50 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: > >> Hi Kevin, >> >> I don''t currently have my computer with me to check the code - so sorry I >> can''t be more helpful. I might have made some of these methods up, so apply >> a good dose of common sense if things didn''t work as expected :) >> >> I believe this should do the trick: >> >> form = agent.current_page.forms.first >> >> form.action = form.action.gsub(...).gsub(...) >> >> form.submit >> >> Forget what I said earlier about the nokogiri stuff and form.submit won''t >> work etc. I wasn''t aware that you can change the form action from mechanize. >> >> If form.submit somehow didn''t work, please post a trace. >> >> Godfrey >> ? >> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >> >> >> On Mon, Feb 25, 2013 at 7:38 PM, Kevin Kornemann <kevin at proofimaging.com>wrote: >> >>> sorry meant I tried: >>> >>> form.attr(''action'', action) >>> >>> to no avail...? >>> >>> On Mon, Feb 25, 2013 at 10:35 PM, Kevin Kornemann < >>> kevin at proofimaging.com> wrote: >>> >>>> actually, this grabbed it: >>>> >>>> action = form.action >>>> >>>> and your gsub worked a charm. >>>> >>>> Just need to get this to submit... Because you''re right form.submit >>>> didn''t work... I tried what you gave me: >>>> >>>> action = form.attr(''action'') >>>> >>>> But undefined meth again on attr... >>>> >>>> On Mon, Feb 25, 2013 at 10:29 PM, Kevin Kornemann < >>>> kevin at proofimaging.com> wrote: >>>> >>>>> Hi Godfrey, >>>>> >>>>> Thanks for your help. Really working hard to figure this out. I ran >>>>> into a road block that is my inexperience with nokogiri and mech. >>>>> >>>>> When I try to grab the action (action = form.attr(''action'')), I get >>>>> undefined method... Here is what I''m doing exactly: >>>>> >>>>> agent = Mechanize.new >>>>> agent.user_agent_alias = ''Mac Safari'' >>>>> page = agent.get(''https://somesite.jsp'') >>>>> >>>>> form = agent.page.forms.first >>>>> action = form.attr(''action'') >>>>> >>>>> and undefined method... >>>>> I tried seeing if I could grab the action various ways to no avail. >>>>> >>>>> My other question is, assuming I do this successfuly, I would normally >>>>> use "form.submit" but you''re saying this won''t work? What should I try? >>>>> >>>>> Thanks again for your help!! >>>>> Kevin >>>>> >>>>> >>>>> On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: >>>>> >>>>>> Hi Kevin, >>>>>> >>>>>> It looks like the "action" attribute of your form contains something >>>>>> along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". >>>>>> The semicolon in here is not strictly a valid character in an URL. Try >>>>>> replacing it with %3B. >>>>>> >>>>>> form = page.at( ...select the form with a selector... ) >>>>>> >>>>>> action = form.attr(''action'') >>>>>> >>>>>> action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') >>>>>> >>>>>> form.attr(''action'', action) >>>>>> >>>>>> # then submit the form as usual (You can''t do form.submit because >>>>>> this form object we have here is a nokogiri node. You need to go through >>>>>> mechanize to submit the form.) >>>>>> >>>>>> Godfrey >>>>>> ? >>>>>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>>>>> >>>>>> >>>>>> On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann < >>>>>> kevin at proofimaging.com> wrote: >>>>>> >>>>>>> Got a form, hitting a button with Mechanize. Thus far have been >>>>>>> going through login steps quite nicely so I know my Mechanize basics are up >>>>>>> to snuff. >>>>>>> >>>>>>> Then I get: >>>>>>> >>>>>>> URI::InvalidURIError: bad URI(is not URI?): >>>>>>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>>>>>> from >>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in >>>>>>> `split'' >>>>>>> from >>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in >>>>>>> `parse'' >>>>>>> from >>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in >>>>>>> `parse'' >>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in >>>>>>> `rescue in resolve'' >>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in >>>>>>> `resolve'' >>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in >>>>>>> `fetch'' >>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in >>>>>>> `post_form'' >>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in >>>>>>> `submit'' >>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in >>>>>>> `submit'' >>>>>>> from (irb):69 >>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in >>>>>>> `start'' >>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in >>>>>>> `start'' >>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in >>>>>>> `<top (required)>'' >>>>>>> from script/rails:6:in `require'' >>>>>>> from script/rails:6:in `<main>'' >>>>>>> >>>>>>> From the googling I''ve done, seems to be related to an invalid >>>>>>> character in the re-direct, but really I have no idea... >>>>>>> >>>>>>> Any way of ignoring these weird characters and continuing? Anyway of >>>>>>> fixing this? >>>>>>> >>>>>>> Best, >>>>>>> Kevin >>>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> 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 >> > > > _______________________________________________ > 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/20130225/5d566def/attachment-0001.html>
So, that got past the URI error, but the system just bounced me to a "session expired" page... Actually last night I did you gsub trick and submitted the new string with a manual agent.post but the same thing happened, it just bounced me to a session expired page. This is the last page (and form) of many pages/forms before it that all have similar action URI strings (with the same weird chars) that don''t raise an mech exceptions. Which leads me to believe this is something about the agent not looking enough like a browser that this site doesn''t like, and this last page is looking at headers or something and bouncing requests from non browsers... But I''m no expert this is just my hunch at this point. Is there a more robust method of setting up mech to look more like a browser??? besides the usual agent.user_agent_alias = ''Windows IE 6'' Headers? Thanks again, Kevin On Tue, Feb 26, 2013 at 1:58 AM, Godfrey Chan <godfreykfc at gmail.com> wrote:> Hi Kevin, > > I finally have access to my computer now, and it turns out the semi colon > in the action is not the corrupt - the colon ("...:-1") was the issue. > (Didn''t notice that before, I thought it was a line number or some sort of > error code. That''s a *really* weird URI.) > > >> require ''mechanize'' > >> agent = Mechanize.new > >> page = agent.get ''http://formtest.dev/form_test.html'' > >> form = page.forms.first > >> form.submit > URI::InvalidURIError: bad URI(is not URI?): > CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 > >> form.action = CGI.escape(form.action) > >> form.submit # this should work now > > If your server fail to URL decode that for some odd reason and refuse to > process that, you can try: > > form.action = ''./'' + form.action > > Hope it helps. > > Godfrey > > > > On Mon, Feb 25, 2013 at 8:06 PM, Kevin Kornemann <kevin at proofimaging.com>wrote: > >> Hi Godfrey, >> >> 1) Thanks again for your help, I really appreciate it. >> 2) yeah, so I can grab the action, gsub it nicely (I see the return). But >> when I ''form.submit'' it errors out on the original URI, as if the new >> version wasn''t changed at all... >> >> I''ll keep trying and let you know how I do. ENough for tonight. >> thanks, >> Kevin >> >> >> On Mon, Feb 25, 2013 at 10:50 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: >> >>> Hi Kevin, >>> >>> I don''t currently have my computer with me to check the code - so >>> sorry I can''t be more helpful. I might have made some of these methods up, >>> so apply a good dose of common sense if things didn''t work as expected :) >>> >>> I believe this should do the trick: >>> >>> form = agent.current_page.forms.first >>> >>> form.action = form.action.gsub(...).gsub(...) >>> >>> form.submit >>> >>> Forget what I said earlier about the nokogiri stuff and form.submit >>> won''t work etc. I wasn''t aware that you can change the form action from >>> mechanize. >>> >>> If form.submit somehow didn''t work, please post a trace. >>> >>> Godfrey >>> ? >>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>> >>> >>> On Mon, Feb 25, 2013 at 7:38 PM, Kevin Kornemann <kevin at proofimaging.com >>> > wrote: >>> >>>> sorry meant I tried: >>>> >>>> form.attr(''action'', action) >>>> >>>> to no avail...? >>>> >>>> On Mon, Feb 25, 2013 at 10:35 PM, Kevin Kornemann < >>>> kevin at proofimaging.com> wrote: >>>> >>>>> actually, this grabbed it: >>>>> >>>>> action = form.action >>>>> >>>>> and your gsub worked a charm. >>>>> >>>>> Just need to get this to submit... Because you''re right form.submit >>>>> didn''t work... I tried what you gave me: >>>>> >>>>> action = form.attr(''action'') >>>>> >>>>> But undefined meth again on attr... >>>>> >>>>> On Mon, Feb 25, 2013 at 10:29 PM, Kevin Kornemann < >>>>> kevin at proofimaging.com> wrote: >>>>> >>>>>> Hi Godfrey, >>>>>> >>>>>> Thanks for your help. Really working hard to figure this out. I ran >>>>>> into a road block that is my inexperience with nokogiri and mech. >>>>>> >>>>>> When I try to grab the action (action = form.attr(''action'')), I get >>>>>> undefined method... Here is what I''m doing exactly: >>>>>> >>>>>> agent = Mechanize.new >>>>>> agent.user_agent_alias = ''Mac Safari'' >>>>>> page = agent.get(''https://somesite.jsp'') >>>>>> >>>>>> form = agent.page.forms.first >>>>>> action = form.attr(''action'') >>>>>> >>>>>> and undefined method... >>>>>> I tried seeing if I could grab the action various ways to no avail. >>>>>> >>>>>> My other question is, assuming I do this successfuly, I would >>>>>> normally use "form.submit" but you''re saying this won''t work? What should I >>>>>> try? >>>>>> >>>>>> Thanks again for your help!! >>>>>> Kevin >>>>>> >>>>>> >>>>>> On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: >>>>>> >>>>>>> Hi Kevin, >>>>>>> >>>>>>> It looks like the "action" attribute of your form contains something >>>>>>> along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". >>>>>>> The semicolon in here is not strictly a valid character in an URL. Try >>>>>>> replacing it with %3B. >>>>>>> >>>>>>> form = page.at( ...select the form with a selector... ) >>>>>>> >>>>>>> action = form.attr(''action'') >>>>>>> >>>>>>> action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') >>>>>>> >>>>>>> form.attr(''action'', action) >>>>>>> >>>>>>> # then submit the form as usual (You can''t do form.submit because >>>>>>> this form object we have here is a nokogiri node. You need to go through >>>>>>> mechanize to submit the form.) >>>>>>> >>>>>>> Godfrey >>>>>>> ? >>>>>>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>>>>>> >>>>>>> >>>>>>> On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann < >>>>>>> kevin at proofimaging.com> wrote: >>>>>>> >>>>>>>> Got a form, hitting a button with Mechanize. Thus far have been >>>>>>>> going through login steps quite nicely so I know my Mechanize basics are up >>>>>>>> to snuff. >>>>>>>> >>>>>>>> Then I get: >>>>>>>> >>>>>>>> URI::InvalidURIError: bad URI(is not URI?): >>>>>>>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>>>>>>> from >>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in >>>>>>>> `split'' >>>>>>>> from >>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in >>>>>>>> `parse'' >>>>>>>> from >>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in >>>>>>>> `parse'' >>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in >>>>>>>> `rescue in resolve'' >>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in >>>>>>>> `resolve'' >>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in >>>>>>>> `fetch'' >>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in >>>>>>>> `post_form'' >>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in >>>>>>>> `submit'' >>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in >>>>>>>> `submit'' >>>>>>>> from (irb):69 >>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in >>>>>>>> `start'' >>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in >>>>>>>> `start'' >>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in >>>>>>>> `<top (required)>'' >>>>>>>> from script/rails:6:in `require'' >>>>>>>> from script/rails:6:in `<main>'' >>>>>>>> >>>>>>>> From the googling I''ve done, seems to be related to an invalid >>>>>>>> character in the re-direct, but really I have no idea... >>>>>>>> >>>>>>>> Any way of ignoring these weird characters and continuing? Anyway >>>>>>>> of fixing this? >>>>>>>> >>>>>>>> Best, >>>>>>>> Kevin >>>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> 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 >>> >> >> >> _______________________________________________ >> 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20130226/9ef16254/attachment.html>
You might try something other than IE6. See http://rubydoc.info/gems/mechanize/Mechanize, scroll down just a bit to see all the options. On Feb 26, 2013, at 6:02 AM, Kevin Kornemann <kevin at proofimaging.com> wrote:> So, that got past the URI error, but the system just bounced me to a "session expired" page... Actually last night I did you gsub trick and submitted the new string with a manual agent.post but the same thing happened, it just bounced me to a session expired page. > > This is the last page (and form) of many pages/forms before it that all have similar action URI strings (with the same weird chars) that don''t raise an mech exceptions. Which leads me to believe this is something about the agent not looking enough like a browser that this site doesn''t like, and this last page is looking at headers or something and bouncing requests from non browsers... But I''m no expert this is just my hunch at this point. > > Is there a more robust method of setting up mech to look more like a browser??? besides the usual agent.user_agent_alias = ''Windows IE 6'' > > Headers? > > Thanks again, > Kevin > > > On Tue, Feb 26, 2013 at 1:58 AM, Godfrey Chan <godfreykfc at gmail.com> wrote: >> Hi Kevin, >> >> I finally have access to my computer now, and it turns out the semi colon in the action is not the corrupt - the colon ("...:-1") was the issue. (Didn''t notice that before, I thought it was a line number or some sort of error code. That''s a *really* weird URI.) >> >> >> require ''mechanize'' >> >> agent = Mechanize.new >> >> page = agent.get ''http://formtest.dev/form_test.html'' >> >> form = page.forms.first >> >> form.submit >> URI::InvalidURIError: bad URI(is not URI?): CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >> >> form.action = CGI.escape(form.action) >> >> form.submit # this should work now >> >> If your server fail to URL decode that for some odd reason and refuse to process that, you can try: >> >> form.action = ''./'' + form.action >> >> Hope it helps. >> >> Godfrey >> >> >> >> On Mon, Feb 25, 2013 at 8:06 PM, Kevin Kornemann <kevin at proofimaging.com> wrote: >>> Hi Godfrey, >>> >>> 1) Thanks again for your help, I really appreciate it. >>> 2) yeah, so I can grab the action, gsub it nicely (I see the return). But when I ''form.submit'' it errors out on the original URI, as if the new version wasn''t changed at all... >>> >>> I''ll keep trying and let you know how I do. ENough for tonight. >>> thanks, >>> Kevin >>> >>> >>> On Mon, Feb 25, 2013 at 10:50 PM, Godfrey Chan <godfreykfc at gmail.com> wrote: >>>> Hi Kevin, >>>> >>>> I don''t currently have my computer with me to check the code - so sorry I can''t be more helpful. I might have made some of these methods up, so apply a good dose of common sense if things didn''t work as expected :) >>>> >>>> I believe this should do the trick: >>>> >>>> form = agent.current_page.forms.first >>>> >>>> form.action = form.action.gsub(...).gsub(...) >>>> >>>> form.submit >>>> >>>> Forget what I said earlier about the nokogiri stuff and form.submit won''t work etc. I wasn''t aware that you can change the form action from mechanize. >>>> >>>> If form.submit somehow didn''t work, please post a trace. >>>> >>>> Godfrey >>>> ? >>>> Sent from Mailbox for iPhone >>>> >>>> >>>> On Mon, Feb 25, 2013 at 7:38 PM, Kevin Kornemann <kevin at proofimaging.com> wrote: >>>>> sorry meant I tried: >>>>> >>>>> >>>>> form.attr(''action'', action) >>>>> >>>>> to no avail...? >>>>> >>>>> On Mon, Feb 25, 2013 at 10:35 PM, Kevin Kornemann <kevin at proofimaging.com> wrote: >>>>>> actually, this grabbed it: >>>>>> >>>>>> action = form.action >>>>>> >>>>>> and your gsub worked a charm. >>>>>> >>>>>> Just need to get this to submit... Because you''re right form.submit didn''t work... I tried what you gave me: >>>>>> >>>>>> action = form.attr(''action'') >>>>>> >>>>>> But undefined meth again on attr... >>>>>> >>>>>> On Mon, Feb 25, 2013 at 10:29 PM, Kevin Kornemann <kevin at proofimaging.com> wrote: >>>>>>> Hi Godfrey, >>>>>>> >>>>>>> Thanks for your help. Really working hard to figure this out. I ran into a road block that is my inexperience with nokogiri and mech. >>>>>>> >>>>>>> When I try to grab the action (action = form.attr(''action'')), I get undefined method... Here is what I''m doing exactly: >>>>>>> >>>>>>> agent = Mechanize.new >>>>>>> agent.user_agent_alias = ''Mac Safari'' >>>>>>> page = agent.get(''https://somesite.jsp'') >>>>>>> >>>>>>> form = agent.page.forms.first >>>>>>> action = form.attr(''action'') >>>>>>> >>>>>>> and undefined method... >>>>>>> I tried seeing if I could grab the action various ways to no avail. >>>>>>> >>>>>>> My other question is, assuming I do this successfuly, I would normally use "form.submit" but you''re saying this won''t work? What should I try? >>>>>>> >>>>>>> Thanks again for your help!! >>>>>>> Kevin >>>>>>> >>>>>>> >>>>>>> On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan <godfreykfc at gmail.com> wrote: >>>>>>>> Hi Kevin, >>>>>>>> >>>>>>>> >>>>>>>> It looks like the "action" attribute of your form contains something along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". The semicolon in here is not strictly a valid character in an URL. Try replacing it with %3B. >>>>>>>> >>>>>>>> form = page.at( ...select the form with a selector... ) >>>>>>>> >>>>>>>> action = form.attr(''action'') >>>>>>>> >>>>>>>> action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') >>>>>>>> >>>>>>>> form.attr(''action'', action) >>>>>>>> >>>>>>>> # then submit the form as usual (You can''t do form.submit because this form object we have here is a nokogiri node. You need to go through mechanize to submit the form.) >>>>>>>> >>>>>>>> Godfrey >>>>>>>> ? >>>>>>>> Sent from Mailbox for iPhone >>>>>>>> >>>>>>>> >>>>>>>> On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann <kevin at proofimaging.com> wrote: >>>>>>>>> Got a form, hitting a button with Mechanize. Thus far have been going through login steps quite nicely so I know my Mechanize basics are up to snuff. >>>>>>>>> >>>>>>>>> >>>>>>>>> Then I get: >>>>>>>>> >>>>>>>>> URI::InvalidURIError: bad URI(is not URI?): CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>>>>>>>> from /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in `split'' >>>>>>>>> from /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in `parse'' >>>>>>>>> from /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in `parse'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in `rescue in resolve'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in `resolve'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in `fetch'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in `post_form'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in `submit'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in `submit'' >>>>>>>>> from (irb):69 >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'' >>>>>>>>> from script/rails:6:in `require'' >>>>>>>>> from script/rails:6:in `<main>'' >>>>>>>>> >>>>>>>>> From the googling I''ve done, seems to be related to an invalid character in the re-direct, but really I have no idea... >>>>>>>>> >>>>>>>>> Any way of ignoring these weird characters and continuing? Anyway of fixing this? >>>>>>>>> >>>>>>>>> Best, >>>>>>>>> Kevin >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> 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 >>> >>> >>> _______________________________________________ >>> 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 > > _______________________________________________ > 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/20130226/625a9836/attachment-0001.html>
Yeah I started with, "Mac Safari" It''s an old site, so I thought try the oldest crappiest browser I could use. But I suppose trying them all will only be slightly futile. Now I''m wondering if it''s a lost cookie thing. I understand Mech tracks these automatically but I see from googling people still also manually store them in a "cookie_jar" pain... On Tue, Feb 26, 2013 at 10:06 AM, Matt White <mattw922 at gmail.com> wrote:> You might try something other than IE6. See > http://rubydoc.info/gems/mechanize/Mechanize, scroll down just a bit to > see all the options. > > > On Feb 26, 2013, at 6:02 AM, Kevin Kornemann <kevin at proofimaging.com> > wrote: > > So, that got past the URI error, but the system just bounced me to a > "session expired" page... Actually last night I did you gsub trick and > submitted the new string with a manual agent.post but the same thing > happened, it just bounced me to a session expired page. > > This is the last page (and form) of many pages/forms before it that all > have similar action URI strings (with the same weird chars) that don''t > raise an mech exceptions. Which leads me to believe this is something about > the agent not looking enough like a browser that this site doesn''t like, > and this last page is looking at headers or something and bouncing requests > from non browsers... But I''m no expert this is just my hunch at this point. > > Is there a more robust method of setting up mech to look more like a > browser??? besides the usual agent.user_agent_alias = ''Windows IE 6'' > > Headers? > > Thanks again, > Kevin > > > On Tue, Feb 26, 2013 at 1:58 AM, Godfrey Chan <godfreykfc at gmail.com>wrote: > >> Hi Kevin, >> >> I finally have access to my computer now, and it turns out the semi colon >> in the action is not the corrupt - the colon ("...:-1") was the issue. >> (Didn''t notice that before, I thought it was a line number or some sort of >> error code. That''s a *really* weird URI.) >> >> >> require ''mechanize'' >> >> agent = Mechanize.new >> >> page = agent.get ''http://formtest.dev/form_test.html'' >> >> form = page.forms.first >> >> form.submit >> URI::InvalidURIError: bad URI(is not URI?): >> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >> >> form.action = CGI.escape(form.action) >> >> form.submit # this should work now >> >> If your server fail to URL decode that for some odd reason and refuse to >> process that, you can try: >> >> form.action = ''./'' + form.action >> >> Hope it helps. >> >> Godfrey >> >> >> >> On Mon, Feb 25, 2013 at 8:06 PM, Kevin Kornemann <kevin at proofimaging.com >> > wrote: >> >>> Hi Godfrey, >>> >>> 1) Thanks again for your help, I really appreciate it. >>> 2) yeah, so I can grab the action, gsub it nicely (I see the return). >>> But when I ''form.submit'' it errors out on the original URI, as if the new >>> version wasn''t changed at all... >>> >>> I''ll keep trying and let you know how I do. ENough for tonight. >>> thanks, >>> Kevin >>> >>> >>> On Mon, Feb 25, 2013 at 10:50 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: >>> >>>> Hi Kevin, >>>> >>>> I don''t currently have my computer with me to check the code - so >>>> sorry I can''t be more helpful. I might have made some of these methods up, >>>> so apply a good dose of common sense if things didn''t work as expected :) >>>> >>>> I believe this should do the trick: >>>> >>>> form = agent.current_page.forms.first >>>> >>>> form.action = form.action.gsub(...).gsub(...) >>>> >>>> form.submit >>>> >>>> Forget what I said earlier about the nokogiri stuff and form.submit >>>> won''t work etc. I wasn''t aware that you can change the form action from >>>> mechanize. >>>> >>>> If form.submit somehow didn''t work, please post a trace. >>>> >>>> Godfrey >>>> ? >>>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>>> >>>> >>>> On Mon, Feb 25, 2013 at 7:38 PM, Kevin Kornemann < >>>> kevin at proofimaging.com> wrote: >>>> >>>>> sorry meant I tried: >>>>> >>>>> form.attr(''action'', action) >>>>> >>>>> to no avail...? >>>>> >>>>> On Mon, Feb 25, 2013 at 10:35 PM, Kevin Kornemann < >>>>> kevin at proofimaging.com> wrote: >>>>> >>>>>> actually, this grabbed it: >>>>>> >>>>>> action = form.action >>>>>> >>>>>> and your gsub worked a charm. >>>>>> >>>>>> Just need to get this to submit... Because you''re right form.submit >>>>>> didn''t work... I tried what you gave me: >>>>>> >>>>>> action = form.attr(''action'') >>>>>> >>>>>> But undefined meth again on attr... >>>>>> >>>>>> On Mon, Feb 25, 2013 at 10:29 PM, Kevin Kornemann < >>>>>> kevin at proofimaging.com> wrote: >>>>>> >>>>>>> Hi Godfrey, >>>>>>> >>>>>>> Thanks for your help. Really working hard to figure this out. I ran >>>>>>> into a road block that is my inexperience with nokogiri and mech. >>>>>>> >>>>>>> When I try to grab the action (action = form.attr(''action'')), I get >>>>>>> undefined method... Here is what I''m doing exactly: >>>>>>> >>>>>>> agent = Mechanize.new >>>>>>> agent.user_agent_alias = ''Mac Safari'' >>>>>>> page = agent.get(''https://somesite.jsp'') >>>>>>> >>>>>>> form = agent.page.forms.first >>>>>>> action = form.attr(''action'') >>>>>>> >>>>>>> and undefined method... >>>>>>> I tried seeing if I could grab the action various ways to no avail. >>>>>>> >>>>>>> My other question is, assuming I do this successfuly, I would >>>>>>> normally use "form.submit" but you''re saying this won''t work? What should I >>>>>>> try? >>>>>>> >>>>>>> Thanks again for your help!! >>>>>>> Kevin >>>>>>> >>>>>>> >>>>>>> On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: >>>>>>> >>>>>>>> Hi Kevin, >>>>>>>> >>>>>>>> It looks like the "action" attribute of your form contains >>>>>>>> something along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". >>>>>>>> The semicolon in here is not strictly a valid character in an URL. Try >>>>>>>> replacing it with %3B. >>>>>>>> >>>>>>>> form = page.at( ...select the form with a selector... ) >>>>>>>> >>>>>>>> action = form.attr(''action'') >>>>>>>> >>>>>>>> action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') >>>>>>>> >>>>>>>> form.attr(''action'', action) >>>>>>>> >>>>>>>> # then submit the form as usual (You can''t do form.submit because >>>>>>>> this form object we have here is a nokogiri node. You need to go through >>>>>>>> mechanize to submit the form.) >>>>>>>> >>>>>>>> Godfrey >>>>>>>> ? >>>>>>>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>>>>>>> >>>>>>>> >>>>>>>> On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann < >>>>>>>> kevin at proofimaging.com> wrote: >>>>>>>> >>>>>>>>> Got a form, hitting a button with Mechanize. Thus far have been >>>>>>>>> going through login steps quite nicely so I know my Mechanize basics are up >>>>>>>>> to snuff. >>>>>>>>> >>>>>>>>> Then I get: >>>>>>>>> >>>>>>>>> URI::InvalidURIError: bad URI(is not URI?): >>>>>>>>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>>>>>>>> from >>>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in >>>>>>>>> `split'' >>>>>>>>> from >>>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in >>>>>>>>> `parse'' >>>>>>>>> from >>>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in >>>>>>>>> `parse'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in >>>>>>>>> `rescue in resolve'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in >>>>>>>>> `resolve'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in >>>>>>>>> `fetch'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in >>>>>>>>> `post_form'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in >>>>>>>>> `submit'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in >>>>>>>>> `submit'' >>>>>>>>> from (irb):69 >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in >>>>>>>>> `start'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in >>>>>>>>> `start'' >>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in >>>>>>>>> `<top (required)>'' >>>>>>>>> from script/rails:6:in `require'' >>>>>>>>> from script/rails:6:in `<main>'' >>>>>>>>> >>>>>>>>> From the googling I''ve done, seems to be related to an invalid >>>>>>>>> character in the re-direct, but really I have no idea... >>>>>>>>> >>>>>>>>> Any way of ignoring these weird characters and continuing? Anyway >>>>>>>>> of fixing this? >>>>>>>>> >>>>>>>>> Best, >>>>>>>>> Kevin >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> 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 >>>> >>> >>> >>> _______________________________________________ >>> 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 >> > > _______________________________________________ > 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20130226/f67004a0/attachment-0001.html>
I doubt that it''s a UA string or cookie issue - I''d very carefully compare the URIs from the previous pages and the offending form target URI. Also, have you tried "form.action = ''./'' + form.action" approach instead of the gsub/CGI.escape approach? It could be that your server doesn''t decode the URL properly and hence missed the session ID. On Tue, Feb 26, 2013 at 7:49 AM, Kevin Kornemann <kevin at proofimaging.com>wrote:> Yeah I started with, "Mac Safari" > > It''s an old site, so I thought try the oldest crappiest browser I could > use. But I suppose trying them all will only be slightly futile. > > Now I''m wondering if it''s a lost cookie thing. I understand Mech tracks > these automatically but I see from googling people still also manually > store them in a "cookie_jar" > > pain... > > > On Tue, Feb 26, 2013 at 10:06 AM, Matt White <mattw922 at gmail.com> wrote: > >> You might try something other than IE6. See >> http://rubydoc.info/gems/mechanize/Mechanize, scroll down just a bit to >> see all the options. >> >> >> On Feb 26, 2013, at 6:02 AM, Kevin Kornemann <kevin at proofimaging.com> >> wrote: >> >> So, that got past the URI error, but the system just bounced me to a >> "session expired" page... Actually last night I did you gsub trick and >> submitted the new string with a manual agent.post but the same thing >> happened, it just bounced me to a session expired page. >> >> This is the last page (and form) of many pages/forms before it that all >> have similar action URI strings (with the same weird chars) that don''t >> raise an mech exceptions. Which leads me to believe this is something about >> the agent not looking enough like a browser that this site doesn''t like, >> and this last page is looking at headers or something and bouncing requests >> from non browsers... But I''m no expert this is just my hunch at this point. >> >> Is there a more robust method of setting up mech to look more like a >> browser??? besides the usual agent.user_agent_alias = ''Windows IE 6'' >> >> Headers? >> >> Thanks again, >> Kevin >> >> >> On Tue, Feb 26, 2013 at 1:58 AM, Godfrey Chan <godfreykfc at gmail.com>wrote: >> >>> Hi Kevin, >>> >>> I finally have access to my computer now, and it turns out the semi >>> colon in the action is not the corrupt - the colon ("...:-1") was the >>> issue. (Didn''t notice that before, I thought it was a line number or some >>> sort of error code. That''s a *really* weird URI.) >>> >>> >> require ''mechanize'' >>> >> agent = Mechanize.new >>> >> page = agent.get ''http://formtest.dev/form_test.html'' >>> >> form = page.forms.first >>> >> form.submit >>> URI::InvalidURIError: bad URI(is not URI?): >>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>> >> form.action = CGI.escape(form.action) >>> >> form.submit # this should work now >>> >>> If your server fail to URL decode that for some odd reason and refuse to >>> process that, you can try: >>> >>> form.action = ''./'' + form.action >>> >>> Hope it helps. >>> >>> Godfrey >>> >>> >>> >>> On Mon, Feb 25, 2013 at 8:06 PM, Kevin Kornemann < >>> kevin at proofimaging.com> wrote: >>> >>>> Hi Godfrey, >>>> >>>> 1) Thanks again for your help, I really appreciate it. >>>> 2) yeah, so I can grab the action, gsub it nicely (I see the return). >>>> But when I ''form.submit'' it errors out on the original URI, as if the new >>>> version wasn''t changed at all... >>>> >>>> I''ll keep trying and let you know how I do. ENough for tonight. >>>> thanks, >>>> Kevin >>>> >>>> >>>> On Mon, Feb 25, 2013 at 10:50 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: >>>> >>>>> Hi Kevin, >>>>> >>>>> I don''t currently have my computer with me to check the code - so >>>>> sorry I can''t be more helpful. I might have made some of these methods up, >>>>> so apply a good dose of common sense if things didn''t work as expected :) >>>>> >>>>> I believe this should do the trick: >>>>> >>>>> form = agent.current_page.forms.first >>>>> >>>>> form.action = form.action.gsub(...).gsub(...) >>>>> >>>>> form.submit >>>>> >>>>> Forget what I said earlier about the nokogiri stuff and form.submit >>>>> won''t work etc. I wasn''t aware that you can change the form action from >>>>> mechanize. >>>>> >>>>> If form.submit somehow didn''t work, please post a trace. >>>>> >>>>> Godfrey >>>>> ? >>>>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>>>> >>>>> >>>>> On Mon, Feb 25, 2013 at 7:38 PM, Kevin Kornemann < >>>>> kevin at proofimaging.com> wrote: >>>>> >>>>>> sorry meant I tried: >>>>>> >>>>>> form.attr(''action'', action) >>>>>> >>>>>> to no avail...? >>>>>> >>>>>> On Mon, Feb 25, 2013 at 10:35 PM, Kevin Kornemann < >>>>>> kevin at proofimaging.com> wrote: >>>>>> >>>>>>> actually, this grabbed it: >>>>>>> >>>>>>> action = form.action >>>>>>> >>>>>>> and your gsub worked a charm. >>>>>>> >>>>>>> Just need to get this to submit... Because you''re right form.submit >>>>>>> didn''t work... I tried what you gave me: >>>>>>> >>>>>>> action = form.attr(''action'') >>>>>>> >>>>>>> But undefined meth again on attr... >>>>>>> >>>>>>> On Mon, Feb 25, 2013 at 10:29 PM, Kevin Kornemann < >>>>>>> kevin at proofimaging.com> wrote: >>>>>>> >>>>>>>> Hi Godfrey, >>>>>>>> >>>>>>>> Thanks for your help. Really working hard to figure this out. I ran >>>>>>>> into a road block that is my inexperience with nokogiri and mech. >>>>>>>> >>>>>>>> When I try to grab the action (action = form.attr(''action'')), I >>>>>>>> get undefined method... Here is what I''m doing exactly: >>>>>>>> >>>>>>>> agent = Mechanize.new >>>>>>>> agent.user_agent_alias = ''Mac Safari'' >>>>>>>> page = agent.get(''https://somesite.jsp'') >>>>>>>> >>>>>>>> form = agent.page.forms.first >>>>>>>> action = form.attr(''action'') >>>>>>>> >>>>>>>> and undefined method... >>>>>>>> I tried seeing if I could grab the action various ways to no avail. >>>>>>>> >>>>>>>> My other question is, assuming I do this successfuly, I would >>>>>>>> normally use "form.submit" but you''re saying this won''t work? What should I >>>>>>>> try? >>>>>>>> >>>>>>>> Thanks again for your help!! >>>>>>>> Kevin >>>>>>>> >>>>>>>> >>>>>>>> On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan <godfreykfc at gmail.com >>>>>>>> > wrote: >>>>>>>> >>>>>>>>> Hi Kevin, >>>>>>>>> >>>>>>>>> It looks like the "action" attribute of your form contains >>>>>>>>> something along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". >>>>>>>>> The semicolon in here is not strictly a valid character in an URL. Try >>>>>>>>> replacing it with %3B. >>>>>>>>> >>>>>>>>> form = page.at( ...select the form with a selector... ) >>>>>>>>> >>>>>>>>> action = form.attr(''action'') >>>>>>>>> >>>>>>>>> action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') >>>>>>>>> >>>>>>>>> form.attr(''action'', action) >>>>>>>>> >>>>>>>>> # then submit the form as usual (You can''t do form.submit because >>>>>>>>> this form object we have here is a nokogiri node. You need to go through >>>>>>>>> mechanize to submit the form.) >>>>>>>>> >>>>>>>>> Godfrey >>>>>>>>> ? >>>>>>>>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>>>>>>>> >>>>>>>>> >>>>>>>>> On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann < >>>>>>>>> kevin at proofimaging.com> wrote: >>>>>>>>> >>>>>>>>>> Got a form, hitting a button with Mechanize. Thus far have been >>>>>>>>>> going through login steps quite nicely so I know my Mechanize basics are up >>>>>>>>>> to snuff. >>>>>>>>>> >>>>>>>>>> Then I get: >>>>>>>>>> >>>>>>>>>> URI::InvalidURIError: bad URI(is not URI?): >>>>>>>>>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>>>>>>>>> from >>>>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in >>>>>>>>>> `split'' >>>>>>>>>> from >>>>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in >>>>>>>>>> `parse'' >>>>>>>>>> from >>>>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in >>>>>>>>>> `parse'' >>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in >>>>>>>>>> `rescue in resolve'' >>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in >>>>>>>>>> `resolve'' >>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in >>>>>>>>>> `fetch'' >>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in >>>>>>>>>> `post_form'' >>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in >>>>>>>>>> `submit'' >>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in >>>>>>>>>> `submit'' >>>>>>>>>> from (irb):69 >>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in >>>>>>>>>> `start'' >>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in >>>>>>>>>> `start'' >>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in >>>>>>>>>> `<top (required)>'' >>>>>>>>>> from script/rails:6:in `require'' >>>>>>>>>> from script/rails:6:in `<main>'' >>>>>>>>>> >>>>>>>>>> From the googling I''ve done, seems to be related to an invalid >>>>>>>>>> character in the re-direct, but really I have no idea... >>>>>>>>>> >>>>>>>>>> Any way of ignoring these weird characters and continuing? Anyway >>>>>>>>>> of fixing this? >>>>>>>>>> >>>>>>>>>> Best, >>>>>>>>>> Kevin >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> 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 >>>>> >>>> >>>> >>>> _______________________________________________ >>>> 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 >>> >> >> _______________________________________________ >> 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 >> > > > _______________________________________________ > 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/20130226/e937b887/attachment-0001.html>
that did it. The identifier strings (no idea if that is what they are called) were all preceded by a path of some sort, and this one wasn''t. So simply adding the ./ before the id did the trick. I''m in! Just like Matthew Broderick in War Games... Can''t express how my gratitude enough for your help. I googled and googled and googled, nothing suggested this, which now that I understand what was happening, well perhaps it''s too simple a topic to deserve a stack overflow post. Anyway, hopefully this helps a fellow newb in the future. Thanks Godfrey. Kevin On Tue, Feb 26, 2013 at 9:43 PM, Godfrey Chan <godfreykfc at gmail.com> wrote:> I doubt that it''s a UA string or cookie issue - I''d very carefully compare > the URIs from the previous pages and the offending form target URI. > > Also, have you tried "form.action = ''./'' + form.action" approach instead > of the gsub/CGI.escape approach? It could be that your server doesn''t > decode the URL properly and hence missed the session ID. > > > On Tue, Feb 26, 2013 at 7:49 AM, Kevin Kornemann <kevin at proofimaging.com>wrote: > >> Yeah I started with, "Mac Safari" >> >> It''s an old site, so I thought try the oldest crappiest browser I could >> use. But I suppose trying them all will only be slightly futile. >> >> Now I''m wondering if it''s a lost cookie thing. I understand Mech tracks >> these automatically but I see from googling people still also manually >> store them in a "cookie_jar" >> >> pain... >> >> >> On Tue, Feb 26, 2013 at 10:06 AM, Matt White <mattw922 at gmail.com> wrote: >> >>> You might try something other than IE6. See >>> http://rubydoc.info/gems/mechanize/Mechanize, scroll down just a bit to >>> see all the options. >>> >>> >>> On Feb 26, 2013, at 6:02 AM, Kevin Kornemann <kevin at proofimaging.com> >>> wrote: >>> >>> So, that got past the URI error, but the system just bounced me to a >>> "session expired" page... Actually last night I did you gsub trick and >>> submitted the new string with a manual agent.post but the same thing >>> happened, it just bounced me to a session expired page. >>> >>> This is the last page (and form) of many pages/forms before it that all >>> have similar action URI strings (with the same weird chars) that don''t >>> raise an mech exceptions. Which leads me to believe this is something about >>> the agent not looking enough like a browser that this site doesn''t like, >>> and this last page is looking at headers or something and bouncing requests >>> from non browsers... But I''m no expert this is just my hunch at this point. >>> >>> Is there a more robust method of setting up mech to look more like a >>> browser??? besides the usual agent.user_agent_alias = ''Windows IE 6'' >>> >>> Headers? >>> >>> Thanks again, >>> Kevin >>> >>> >>> On Tue, Feb 26, 2013 at 1:58 AM, Godfrey Chan <godfreykfc at gmail.com>wrote: >>> >>>> Hi Kevin, >>>> >>>> I finally have access to my computer now, and it turns out the semi >>>> colon in the action is not the corrupt - the colon ("...:-1") was the >>>> issue. (Didn''t notice that before, I thought it was a line number or some >>>> sort of error code. That''s a *really* weird URI.) >>>> >>>> >> require ''mechanize'' >>>> >> agent = Mechanize.new >>>> >> page = agent.get ''http://formtest.dev/form_test.html'' >>>> >> form = page.forms.first >>>> >> form.submit >>>> URI::InvalidURIError: bad URI(is not URI?): >>>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>>> >> form.action = CGI.escape(form.action) >>>> >> form.submit # this should work now >>>> >>>> If your server fail to URL decode that for some odd reason and refuse >>>> to process that, you can try: >>>> >>>> form.action = ''./'' + form.action >>>> >>>> Hope it helps. >>>> >>>> Godfrey >>>> >>>> >>>> >>>> On Mon, Feb 25, 2013 at 8:06 PM, Kevin Kornemann < >>>> kevin at proofimaging.com> wrote: >>>> >>>>> Hi Godfrey, >>>>> >>>>> 1) Thanks again for your help, I really appreciate it. >>>>> 2) yeah, so I can grab the action, gsub it nicely (I see the return). >>>>> But when I ''form.submit'' it errors out on the original URI, as if the new >>>>> version wasn''t changed at all... >>>>> >>>>> I''ll keep trying and let you know how I do. ENough for tonight. >>>>> thanks, >>>>> Kevin >>>>> >>>>> >>>>> On Mon, Feb 25, 2013 at 10:50 PM, Godfrey Chan <godfreykfc at gmail.com>wrote: >>>>> >>>>>> Hi Kevin, >>>>>> >>>>>> I don''t currently have my computer with me to check the code - so >>>>>> sorry I can''t be more helpful. I might have made some of these methods up, >>>>>> so apply a good dose of common sense if things didn''t work as expected :) >>>>>> >>>>>> I believe this should do the trick: >>>>>> >>>>>> form = agent.current_page.forms.first >>>>>> >>>>>> form.action = form.action.gsub(...).gsub(...) >>>>>> >>>>>> form.submit >>>>>> >>>>>> Forget what I said earlier about the nokogiri stuff and form.submit >>>>>> won''t work etc. I wasn''t aware that you can change the form action from >>>>>> mechanize. >>>>>> >>>>>> If form.submit somehow didn''t work, please post a trace. >>>>>> >>>>>> Godfrey >>>>>> ? >>>>>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>>>>> >>>>>> >>>>>> On Mon, Feb 25, 2013 at 7:38 PM, Kevin Kornemann < >>>>>> kevin at proofimaging.com> wrote: >>>>>> >>>>>>> sorry meant I tried: >>>>>>> >>>>>>> form.attr(''action'', action) >>>>>>> >>>>>>> to no avail...? >>>>>>> >>>>>>> On Mon, Feb 25, 2013 at 10:35 PM, Kevin Kornemann < >>>>>>> kevin at proofimaging.com> wrote: >>>>>>> >>>>>>>> actually, this grabbed it: >>>>>>>> >>>>>>>> action = form.action >>>>>>>> >>>>>>>> and your gsub worked a charm. >>>>>>>> >>>>>>>> Just need to get this to submit... Because you''re right form.submit >>>>>>>> didn''t work... I tried what you gave me: >>>>>>>> >>>>>>>> action = form.attr(''action'') >>>>>>>> >>>>>>>> But undefined meth again on attr... >>>>>>>> >>>>>>>> On Mon, Feb 25, 2013 at 10:29 PM, Kevin Kornemann < >>>>>>>> kevin at proofimaging.com> wrote: >>>>>>>> >>>>>>>>> Hi Godfrey, >>>>>>>>> >>>>>>>>> Thanks for your help. Really working hard to figure this out. I >>>>>>>>> ran into a road block that is my inexperience with nokogiri and mech. >>>>>>>>> >>>>>>>>> When I try to grab the action (action = form.attr(''action'')), I >>>>>>>>> get undefined method... Here is what I''m doing exactly: >>>>>>>>> >>>>>>>>> agent = Mechanize.new >>>>>>>>> agent.user_agent_alias = ''Mac Safari'' >>>>>>>>> page = agent.get(''https://somesite.jsp'') >>>>>>>>> >>>>>>>>> form = agent.page.forms.first >>>>>>>>> action = form.attr(''action'') >>>>>>>>> >>>>>>>>> and undefined method... >>>>>>>>> I tried seeing if I could grab the action various ways to no avail. >>>>>>>>> >>>>>>>>> My other question is, assuming I do this successfuly, I would >>>>>>>>> normally use "form.submit" but you''re saying this won''t work? What should I >>>>>>>>> try? >>>>>>>>> >>>>>>>>> Thanks again for your help!! >>>>>>>>> Kevin >>>>>>>>> >>>>>>>>> >>>>>>>>> On Mon, Feb 25, 2013 at 9:06 PM, Godfrey Chan < >>>>>>>>> godfreykfc at gmail.com> wrote: >>>>>>>>> >>>>>>>>>> Hi Kevin, >>>>>>>>>> >>>>>>>>>> It looks like the "action" attribute of your form contains >>>>>>>>>> something along the lines of "CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz". >>>>>>>>>> The semicolon in here is not strictly a valid character in an URL. Try >>>>>>>>>> replacing it with %3B. >>>>>>>>>> >>>>>>>>>> form = page.at( ...select the form with a selector... ) >>>>>>>>>> >>>>>>>>>> action = form.attr(''action'') >>>>>>>>>> >>>>>>>>>> action = action.gsub('';'',''%3B'').gsub(''='',''%3D'') >>>>>>>>>> >>>>>>>>>> form.attr(''action'', action) >>>>>>>>>> >>>>>>>>>> # then submit the form as usual (You can''t do form.submit because >>>>>>>>>> this form object we have here is a nokogiri node. You need to go through >>>>>>>>>> mechanize to submit the form.) >>>>>>>>>> >>>>>>>>>> Godfrey >>>>>>>>>> ? >>>>>>>>>> Sent from Mailbox <https://bit.ly/SZvoJe> for iPhone >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Mon, Feb 25, 2013 at 4:01 PM, Kevin Kornemann < >>>>>>>>>> kevin at proofimaging.com> wrote: >>>>>>>>>> >>>>>>>>>>> Got a form, hitting a button with Mechanize. Thus far have been >>>>>>>>>>> going through login steps quite nicely so I know my Mechanize basics are up >>>>>>>>>>> to snuff. >>>>>>>>>>> >>>>>>>>>>> Then I get: >>>>>>>>>>> >>>>>>>>>>> URI::InvalidURIError: bad URI(is not URI?): >>>>>>>>>>> CBMenu.jsp;jsessionid=0000FWXUFvwFz8oQcES43L6CCz1:-1 >>>>>>>>>>> from >>>>>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:176:in >>>>>>>>>>> `split'' >>>>>>>>>>> from >>>>>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:211:in >>>>>>>>>>> `parse'' >>>>>>>>>>> from >>>>>>>>>>> /Users/kevin/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/uri/common.rb:747:in >>>>>>>>>>> `parse'' >>>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:621:in >>>>>>>>>>> `rescue in resolve'' >>>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:618:in >>>>>>>>>>> `resolve'' >>>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:214:in >>>>>>>>>>> `fetch'' >>>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:1229:in >>>>>>>>>>> `post_form'' >>>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize.rb:515:in >>>>>>>>>>> `submit'' >>>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/mechanize-2.5.1/lib/mechanize/form.rb:178:in >>>>>>>>>>> `submit'' >>>>>>>>>>> from (irb):69 >>>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in >>>>>>>>>>> `start'' >>>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in >>>>>>>>>>> `start'' >>>>>>>>>>> from /Users/kevin/.rvm/gems/ruby-1.9.3-p286 at texas/gems/railties-3.2.12/lib/rails/commands.rb:41:in >>>>>>>>>>> `<top (required)>'' >>>>>>>>>>> from script/rails:6:in `require'' >>>>>>>>>>> from script/rails:6:in `<main>'' >>>>>>>>>>> >>>>>>>>>>> From the googling I''ve done, seems to be related to an invalid >>>>>>>>>>> character in the re-direct, but really I have no idea... >>>>>>>>>>> >>>>>>>>>>> Any way of ignoring these weird characters and continuing? >>>>>>>>>>> Anyway of fixing this? >>>>>>>>>>> >>>>>>>>>>> Best, >>>>>>>>>>> Kevin >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> _______________________________________________ >>>>>>>>>> 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 >>>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> 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 >>>> >>> >>> _______________________________________________ >>> 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 >>> >> >> >> _______________________________________________ >> 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20130226/3c396544/attachment-0001.html>