Hi all, I''ve a problem when submitting a form : the URL seems to be invalid. I really don''t see the way I should try to solve that problem. I searched on the web, but didn''t found any kind of that problem. Here is the code : require ''mechanize'' agent = WWW::Mechanize.new page = agent.get(''http://www.voyages-sncf.com/leisure/fr/launch/home/'') # the form isn''t on the main page, and it''s necessary to follow that # link to get a session on the site (local cookie) link = page.links.text("train") page = agent.click(link) form = page.forms.first # filling the form form.ORIGIN_CITY = "paris" form.DESTINATION_CITY = "lille" # submit page = agent.submit(form, form.buttons.first) Thanks, Bruno Duy?
You didn''t mention the error or however the problem presented itself. Care to share? :) Mike B. Quoting bruno <bigoudi32 at yahoo.fr>:> Hi all, > > I''ve a problem when submitting a form : the URL seems to be invalid. I really > don''t see the way I should try to solve that problem. I searched on the web, > but didn''t found any kind of that problem. > > Here is the code : > > > > require ''mechanize'' > > agent = WWW::Mechanize.new > page = agent.get(''http://www.voyages-sncf.com/leisure/fr/launch/home/'') > > # the form isn''t on the main page, and it''s necessary to follow that > # link to get a session on the site (local cookie) > link = page.links.text("train") > page = agent.click(link) > > form = page.forms.first > # filling the form > form.ORIGIN_CITY = "paris" > form.DESTINATION_CITY = "lille" > > # submit > page = agent.submit(form, form.buttons.first) > > > > > Thanks, > Bruno Duy? > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users >---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
Yes indeed ... Here is the error message : $ ruby sncf.rb /usr/lib/ruby/1.8/uri/common.rb:436:in `split'': bad URI(is not URI?): http://www.voyages-sncf.com/dynamic/_SvTermCommVoySaisie?_TMS=1174469615530&_DLG=SvTermCommVoySaisie&_LANG=FR&_AGENCY=VSC&_AGENCY=VSC (URI::InvalidURIError) from /usr/lib/ruby/1.8/uri/common.rb:485:in `parse'' from /usr/lib/ruby/1.8/mechanize.rb:238:in `to_absolute_uri'' from /usr/lib/ruby/1.8/mechanize.rb:198:in `submit'' from sncf.rb:16 Thanks I''m sorry for that; but it''s the fisrt program I plan to do in Ruby. I like Runy so much and really wanted to do that GPL software for mounths that I can''t let it down now. Bruno Le mercredi 21 mars 2007 06:16, barsalou a ?crit?:> You didn''t mention the error or however the problem presented itself. > Care to share? :) > > Mike B. > > Quoting bruno <bigoudi32 at yahoo.fr>: > > Hi all, > > > > I''ve a problem when submitting a form : the URL seems to be invalid. I > > really don''t see the way I should try to solve that problem. I searched > > on the web, but didn''t found any kind of that problem. > > > > Here is the code : > > > > > > > > require ''mechanize'' > > > > agent = WWW::Mechanize.new > > page = agent.get(''http://www.voyages-sncf.com/leisure/fr/launch/home/'') > > > > # the form isn''t on the main page, and it''s necessary to follow that > > # link to get a session on the site (local cookie) > > link = page.links.text("train") > > page = agent.click(link) > > > > form = page.forms.first > > # filling the form > > form.ORIGIN_CITY = "paris" > > form.DESTINATION_CITY = "lille" > > > > # submit > > page = agent.submit(form, form.buttons.first) > > > > > > > > > > Thanks, > > Bruno Duy? > > _______________________________________________ > > Mechanize-users mailing list > > Mechanize-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/mechanize-users > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users
Aaron Patterson
2007-Mar-21 15:47 UTC
[Mechanize-users] bad URI problem when submitting a form
On 3/21/07, bruno <bigoudi32 at yahoo.fr> wrote:> Yes indeed ... > > Here is the error message : > > $ ruby sncf.rb > /usr/lib/ruby/1.8/uri/common.rb:436:in `split'': bad URI(is not URI?): > http://www.voyages-sncf.com/dynamic/_SvTermCommVoySaisie?_TMS=1174469615530&_DLG=SvTermCommVoySaisie&_LANG=FR&_AGENCY=VSC&_AGENCY=VSC > (URI::InvalidURIError) > from /usr/lib/ruby/1.8/uri/common.rb:485:in `parse'' > from /usr/lib/ruby/1.8/mechanize.rb:238:in `to_absolute_uri'' > from /usr/lib/ruby/1.8/mechanize.rb:198:in `submit'' > from sncf.rb:16 >Ah. Looks as if you have html entities that are not being decoded before the form is submitted. This is definitely a bug. I will fix this for the next release, but in the mean time you can decode the form action before the form posts. Just use the htmlentities gem: http://rubyforge.org/projects/htmlentities/ Sorry about this, I will get it fixed quickily! -- Aaron Patterson http://tenderlovemaking.com/
Ok, thanks for reply. I''ll try to decode the form action using htmlentities. When do you think the next release will be able ? Thanks very much. Bruno Le mercredi 21 mars 2007 16:47, Aaron Patterson a ?crit?:> On 3/21/07, bruno <bigoudi32 at yahoo.fr> wrote: > > Yes indeed ... > > > > Here is the error message : > > > > $ ruby sncf.rb > > /usr/lib/ruby/1.8/uri/common.rb:436:in `split'': bad URI(is not URI?): > > http://www.voyages-sncf.com/dynamic/_SvTermCommVoySaisie?_TMS=11744696155 > >30&_DLG=SvTermCommVoySaisie&_LANG=FR&_AGENCY=VSC&_AGEN > >CY=VSC (URI::InvalidURIError) > > from /usr/lib/ruby/1.8/uri/common.rb:485:in `parse'' > > from /usr/lib/ruby/1.8/mechanize.rb:238:in `to_absolute_uri'' > > from /usr/lib/ruby/1.8/mechanize.rb:198:in `submit'' > > from sncf.rb:16 > > Ah. Looks as if you have html entities that are not being decoded > before the form is submitted. This is definitely a bug. I will fix > this for the next release, but in the mean time you can decode the > form action before the form posts. Just use the htmlentities gem: > > http://rubyforge.org/projects/htmlentities/ > > Sorry about this, I will get it fixed quickily!
Aaron Patterson
2007-Mar-22 15:13 UTC
[Mechanize-users] bad URI problem when submitting a form
On 3/22/07, bruno <bigoudi32 at yahoo.fr> wrote:> > Ok, thanks for reply. I''ll try to decode the form action using > htmlentities. > When do you think the next release will be able ?I have one more bug to fix, and I''ll do a release. That should be sometime this weekend. -- Aaron Patterson http://tenderlovemaking.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20070322/3772ec63/attachment.html
Oh, you''re quick ! I thought that the release will be in a mounth. I''m lucky. So I''ll wait for that and enjoy my week end with my girl friend ;) Good luck for the release ! Bruno Duy? Le jeudi 22 mars 2007 16:13, Aaron Patterson a ?crit?:> On 3/22/07, bruno <bigoudi32 at yahoo.fr> wrote: > > Ok, thanks for reply. I''ll try to decode the form action using > > htmlentities. > > When do you think the next release will be able ? > > I have one more bug to fix, and I''ll do a release. That should be sometime > this weekend.