hi there, I''m not sure if it is better to use the ml or the forum so I ended to post on both ... I''m trying to login into a page that is using javascript to set a cookie: <script language="JavaScript"> {text "\n" " \n" " \n" " document.cookie = ''vhp_js=v995105608h85339294p;path=/;domain=.venere.com;expire=0''; [...] can you give me an hint on how to add a cookie to the cookie jar? I tried js_cookie WWW::Mechanize::Cookie.new(''/'',"vhp_js=v1847355112h431970412p;path=/;domain=.venere.com;expire=0") so that I can do agent.cookie_jar.add('''',js_cookie) but this is not parsing the cookie in the way I expect it thanks Claudio
Hi Claudio, On Mon, Feb 05, 2007 at 03:00:36PM +0100, Claudio Belotti wrote:> hi there, > I''m not sure if it is better to use the ml or the forum so I ended to > post on both ...Either place is fine, but I like the mailing list better.> > > I''m trying to login into a page that is using javascript to set a cookie: > > <script language="JavaScript"> {text "\n" " \n" " \n" " document.cookie > = ''vhp_js=v995105608h85339294p;path=/;domain=.venere.com;expire=0''; > > [...] > > can you give me an hint on how to add a cookie to the cookie jar? > > I tried > js_cookie > WWW::Mechanize::Cookie.new(''/'',"vhp_js=v1847355112h431970412p;path=/;domain=.venere.com;expire=0")You''re close. You''ll need the URI from the page you want to set the cookie with, and the cookie string itself. Then use the "parse" method on WWW::Mechanize::Cookie. For example: mech = WWW::Mechanize.new page = mech.get(''http://localhost/'') WWW::Mechanize::Cookie.parse(page.uri, "vhp_js=v1847355112h431970412p;path=/;domain=.venere.com;expire=0") { |c| mech.cookie_jar.add(page.uri, c) } Hope that helps. -- Aaron Patterson http://tenderlovemaking.com/
Hi Aaron, on 05/02/2007 17:48 Aaron Patterson wrote:> You''re close. You''ll need the URI from the page you want to set the > cookie with, and the cookie string itself. Then use the "parse" method > on WWW::Mechanize::Cookie. For example: > > mech = WWW::Mechanize.new > page = mech.get(''http://localhost/'') > WWW::Mechanize::Cookie.parse(page.uri, > "vhp_js=v1847355112h431970412p;path=/;domain=.venere.com;expire=0") { |c| > mech.cookie_jar.add(page.uri, c) > } > Hope that helps.yes, thank you for your help, now I can login into the site get some informations and logout I found Mechanize really helpful. regards Claudio