From rdpoor at gmail.com Thu Sep 8 13:20:52 2011 From: rdpoor at gmail.com (Robert Poor) Date: Thu, 8 Sep 2011 10:20:52 -0700 Subject: [Mechanize-users] setting a form field creates duplicate fields? Message-ID: I receive a form, I set some fields, I post the form. ?It all seems to work, along these lines: form['__EVENTTARGET'] = 'objTimePeriods$rlPeriod$1' form['__EVENTARGUMENT'] = '' ? ? form['objTimePeriods$rlPeriod'] = 2 ? ? agent.submit(form) But when I look at what's going out over the wire (thanks to the delightful www.charlesproxy.com), I see the following being posted: objTimePeriods$rlPeriod: 2 __EVENTTARGET: objTimePeriods$rlPeriod$1 __EVENTARGUMENT: objTimePeriods$rlPeriod: 1 Notice that the 'objTimePeriods$rlPeriod' field appears twice -- the '1' was the previous value of the form before I set it to '2'. I've quadruple-checked the spelling and punctuation (even in the raw transmitted byte stream), and they really do have the same field names. My code seems to work, but this may be just luck. Am I doing something wrong? Do I need to check for the presence of a form field before I set it? From skurt.holding at gmail.com Sat Sep 17 04:01:47 2011 From: skurt.holding at gmail.com (Skurt) Date: Sat, 17 Sep 2011 10:01:47 +0200 Subject: [Mechanize-users] Mechanize authentication Message-ID: Hello, I'm trying to access authenticated web using mechanize 2.0.1. Hopefully, Im not mistaken somewhere else, Im not really an IT expert, so I'll be verbose, just to be sure. I was able to break through what I believe is BASIC AUTHENTICATON with this code: require "rubygems" require 'mechanize' agent = Mechanize.new agent.basic_auth('admin:', 'kloktat5x') agent.get('http://10.0.0.138:8080/') it's accessing my router administration and it works fine. Where I have problems is with web-based or cookie-based authentication, it is this kind where you enter your usename and password into a html form and hit some process or submit button. Well, my code is this: (please mind confidentiality of my personal information and be so kind and do not misuse it) require 'rubygems' require 'logger' require 'mechanize' agent = Mechanize.new {|a| a.log = Logger.new(STDERR) } #agent.set_proxy('a-proxy', '8080') page = agent.get 'http://www.hofyland.cz/' form = page.forms.first form.hlnick = 'skurt' form.hlpsw = 'sptnkn34' page = agent.submit form output = File.open("output.html", "w") { |file| file << page.body } and you can try what the output.html will look like afterwards, It'll be body of the login page - the script doesnt authenticate against the web, it simply reloads the page and saves the body. Is someone who have similar experiences, who may be able to solve this kind of problem out there? With my best regars Jan Kadera From ohgaru.takanori at mb.mt-pharma.co.jp Sat Sep 17 09:02:15 2011 From: ohgaru.takanori at mb.mt-pharma.co.jp (ohgaru takanori) Date: Sat, 17 Sep 2011 22:02:15 +0900 Subject: [Mechanize-users] =?iso-2022-jp?b?VGFrYW5vcmkgOTMwMzgwNyBPb2dh?= =?iso-2022-jp?b?cnUgIBskQiRPSVQ6XyRLJDckRiQqJGokXiQ5ISMbKEI=?= Message-ID: 2011/09/17 ????????????*2011/09/24 ?????????* Mail to you after back to the office. From oscartheduck at gmail.com Sun Sep 18 01:34:46 2011 From: oscartheduck at gmail.com (James Harrison) Date: Sat, 17 Sep 2011 23:34:46 -0600 Subject: [Mechanize-users] Mechanize authentication In-Reply-To: References: Message-ID: Hey Jan, This isn't an answer, but you should know this is a public mailing list that anyone can subscribe to. You just sent your password out to the world -- you should change it as soon as possible. On Sep 17, 2011, at 2:01 AM, Skurt wrote: > Hello, > I'm trying to access authenticated web using mechanize 2.0.1. > Hopefully, Im not mistaken somewhere else, Im not really an IT expert, > so I'll be verbose, just to be sure. > > I was able to break through what I believe is BASIC AUTHENTICATON with > this code: > require "rubygems" > require 'mechanize' > agent = Mechanize.new > agent.basic_auth('admin:', 'kloktat5x') > agent.get('http://10.0.0.138:8080/') > > it's accessing my router administration and it works fine. > Where I have problems is with web-based or cookie-based > authentication, it is this kind where you enter your usename and > password into a html form and hit some process or submit button. > > Well, my code is this: > (please mind confidentiality of my personal information and be so kind > and do not misuse it) > > require 'rubygems' > require 'logger' > require 'mechanize' > > agent = Mechanize.new {|a| a.log = Logger.new(STDERR) } > #agent.set_proxy('a-proxy', '8080') > page = agent.get 'http://www.hofyland.cz/' > > > form = page.forms.first > form.hlnick = 'skurt' > form.hlpsw = 'sptnkn34' > > page = agent.submit form > > output = File.open("output.html", "w") { |file| file << page.body } > > and you can try what the output.html will look like afterwards, It'll > be body of the login page - the script doesnt authenticate against the > web, it simply reloads the page and saves the body. > > Is someone who have similar experiences, who may be able to solve this > kind of problem out there? > > With my best regars > Jan Kadera > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users From skurt.holding at gmail.com Sun Sep 18 07:21:26 2011 From: skurt.holding at gmail.com (Skurt) Date: Sun, 18 Sep 2011 13:21:26 +0200 Subject: [Mechanize-users] Mechanize authentication In-Reply-To: References: Message-ID: I know, thats why I chosed to send you my password to a page I don't mind the security of that much. And hopefully someone will help soon and Ill be able to change it :) Best regards Jan Kadera 2011/9/18 James Harrison : > Hey Jan, > > This isn't an answer, but you should know this is a public mailing list that anyone can subscribe to. You just sent your password out to the world -- you should change it as soon as possible. > > > On Sep 17, 2011, at 2:01 AM, Skurt wrote: > >> Hello, >> I'm trying to access authenticated web using mechanize 2.0.1. >> Hopefully, Im not mistaken somewhere else, Im not really an IT expert, >> so I'll be verbose, just to be sure. >> >> I was able to break through what I believe is BASIC AUTHENTICATON with >> this code: >> require "rubygems" >> require 'mechanize' >> agent = Mechanize.new >> agent.basic_auth('admin:', 'kloktat5x') >> agent.get('http://10.0.0.138:8080/') >> >> it's accessing my router administration and it works fine. >> Where I have problems is with web-based or cookie-based >> authentication, it is this kind where you enter your usename and >> password into a html form and hit some process or submit button. >> >> Well, my code is this: >> (please mind confidentiality of my personal information and be so kind >> and do not misuse it) >> >> require 'rubygems' >> require 'logger' >> require 'mechanize' >> >> agent = Mechanize.new {|a| a.log = Logger.new(STDERR) } >> #agent.set_proxy('a-proxy', '8080') >> page = agent.get 'http://www.hofyland.cz/' >> >> >> form = page.forms.first >> form.hlnick = 'skurt' >> form.hlpsw = 'sptnkn34' >> >> page = agent.submit form >> >> output = File.open("output.html", "w") { |file| ?file << page.body } >> >> and you can try what the output.html will look like afterwards, It'll >> be body of the login page - the script doesnt authenticate against the >> web, it simply reloads the page and saves the body. >> >> Is someone who have similar experiences, who may be able to solve this >> kind of problem out there? >> >> With my best regars >> Jan Kadera >> _______________________________________________ >> 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 > -- S p??n?m p?kn?ho dne Jan Kadera From skurt.holding at gmail.com Mon Sep 19 08:41:12 2011 From: skurt.holding at gmail.com (Skurt) Date: Mon, 19 Sep 2011 14:41:12 +0200 Subject: [Mechanize-users] Mechanize authentication In-Reply-To: References: Message-ID: I figured one thing. What I' trying to authenticate against is session based authentication (requiring cookies if I'm not mistaken), can this be where I'm failing. Am I supposed to managing cookies with mechanize somehow? My best regards Jan Kadera 2011/9/18 Skurt : > I know, thats why I chosed to send you my password to a page I don't > mind the security of that much. > And hopefully someone will help soon and Ill be able to change it :) > > Best regards > Jan Kadera > > > 2011/9/18 James Harrison : >> Hey Jan, >> >> This isn't an answer, but you should know this is a public mailing list that anyone can subscribe to. You just sent your password out to the world -- you should change it as soon as possible. >> >> >> On Sep 17, 2011, at 2:01 AM, Skurt wrote: >> >>> Hello, >>> I'm trying to access authenticated web using mechanize 2.0.1. >>> Hopefully, Im not mistaken somewhere else, Im not really an IT expert, >>> so I'll be verbose, just to be sure. >>> >>> I was able to break through what I believe is BASIC AUTHENTICATON with >>> this code: >>> require "rubygems" >>> require 'mechanize' >>> agent = Mechanize.new >>> agent.basic_auth('admin:', 'kloktat5x') >>> agent.get('http://10.0.0.138:8080/') >>> >>> it's accessing my router administration and it works fine. >>> Where I have problems is with web-based or cookie-based >>> authentication, it is this kind where you enter your usename and >>> password into a html form and hit some process or submit button. >>> >>> Well, my code is this: >>> (please mind confidentiality of my personal information and be so kind >>> and do not misuse it) >>> >>> require 'rubygems' >>> require 'logger' >>> require 'mechanize' >>> >>> agent = Mechanize.new {|a| a.log = Logger.new(STDERR) } >>> #agent.set_proxy('a-proxy', '8080') >>> page = agent.get 'http://www.hofyland.cz/' >>> >>> >>> form = page.forms.first >>> form.hlnick = 'skurt' >>> form.hlpsw = 'sptnkn34' >>> >>> page = agent.submit form >>> >>> output = File.open("output.html", "w") { |file| ?file << page.body } >>> >>> and you can try what the output.html will look like afterwards, It'll >>> be body of the login page - the script doesnt authenticate against the >>> web, it simply reloads the page and saves the body. >>> >>> Is someone who have similar experiences, who may be able to solve this >>> kind of problem out there? >>> >>> With my best regars >>> Jan Kadera >>> _______________________________________________ >>> 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 >> > > > > -- > S p??n?m p?kn?ho dne > Jan Kadera > -- S p??n?m p?kn?ho dne Jan Kadera