Fail to parse page after redirect in login form

Hi all,

My code is,

agent =
page = agent.get(“”)
link = page.links.find {|l| l.text =~ /Sign in/}
page =
form = page.forms.first
form.fields.find {|f| == “session_login” }.value = “linkedin_id”
form.fields.find {|f| == “session_password” }.value = “password”
page = agent.submit(form, form.buttons.first)
puts page.body

It gives me the same page as sign in. The result is not the redirected
home page.
Multiple redirects are there so there could be a problem with cookies or
may be the problem with code.

Can anyone help me?

Thanks in advance.