开发者

Issues logging in LinkedIn with ruby mechanize

开发者 https://www.devze.com 2022-12-24 12:39 出处:网络
this week I\'m having problems logging in LinkedIn using ruby mechanize. My code is as follows: agent = WWW::Mechanize.new

this week I'm having problems logging in LinkedIn using ruby mechanize. My code is as follows:

agent = WWW::Mechanize.new
home_page = agent.get('http://www.linkedin.com')
sign_in_link = home_page.links.find{|link| link.text == "Sign In"}
login_form = sign_in_link.click.form('login')
# with email and password variables properly set
login_form.set_fields(:session_key => email, :session_password => password)
return_page = agent.submit(login_form, login_form.buttons.first)

Last week it worked OK but now it's failing, the return_page variable shows a 'redirecting...' message but when I use the same agent to fetch 'http://www.linkedin.com/home', it's as if I've never signed in (although cookies show otherwise). Can someone try to dupli开发者_如何转开发cate this error?

Thanks in advance.


In our case we succeded using curl inside our controller, here is a snippet of what we do, we do a curl call to log in and store the cookies in a file named j and then use it for every subsequent request, hacky but works in the meantime.

 curl_login = `curl --cookie-jar j -so/dev/null -Fsession_login= -Fsession_rikey= -Fsession_key=#{contact} -Fsession_password=#{password} https://www.linkedin.com/secure/login?trk=hb_signin`

 curl_for_profile = `curl --cookie j "#{profile_url}"`

Let me know if you have any question

0

精彩评论

暂无评论...
验证码 换一张
取 消