Fail to parse page after redirect in login form

Hi all,

My code is,

agent = WWW::Mechanize.new
page = agent.get(“https://www.linkedin.com”)
link = page.links.find {|l| l.text =~ /Sign in/}
page = agent.click(link)
form = page.forms.first
form.fields.find {|f| f.name == “session_login” }.value = “linkedin_id”
form.fields.find {|f| f.name == “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.