Mechanize and Cookies


#1

I am trying to access some google stuff (summer of code :slight_smile: which
requires that I am signed in - when I run the code below it says “Your
browser’s cookie functionality is turned off. Please turn it on”

Mechanize seems to support cookies, but I must be doing something wrong.

Thanks
pth


require ‘mechanize’

agent = WWW::Mechanize.new {|a| a.log = Logger.new(STDERR) }
page = agent.get(‘http://www.google.com/’)

link = page.links.text(/sign\s*in/i).first
page = agent.click(link)
form = page.forms[0]

email = form.fields.find { |f| f.name =~ /email/i }
email.value = ‘email addr’
passwd = form.fields.find { |f| f.name =~ /passwd/i }
passwd.value = ‘pass word’

submit = form.buttons.find { |b| b.value =~ /sign\s*in/i }
page = agent.submit(form, submit)
puts page.body


#2

On 5/13/06, Aaron P. removed_email_address@domain.invalid wrote:

Hey Patrick, it doesn’t look like you were doing anything wrong. It

Thanks so much
pth


#3

On Sat, May 13, 2006 at 03:46:32AM +0900, Patrick H. wrote:

I am trying to access some google stuff (summer of code :slight_smile: which
requires that I am signed in - when I run the code below it says “Your
browser’s cookie functionality is turned off. Please turn it on”

Mechanize seems to support cookies, but I must be doing something wrong.

[snip]

Hey Patrick, it doesn’t look like you were doing anything wrong. It
looks like google doesn’t send a space after semicolons in the
‘Set-Cookie’ string, and the cookie parser couldn’t handle that. I
fixed the problem, and it should be available in the next release. If
you need it before that, just check out the current release branch:

svn co svn://rubyforge.org/var/svn/mechanize/branches/RB-0.4.5

and build the gem:

rake package

If you run in to any troubles, just send mail to the mechanize-devel
list:

http://rubyforge.org/mail/?group_id=1453

HTH

–Aaron