2015-12-22 87 views
0

我使用下面的代码: -无法用机械化登录到rottentomatoes.com

require 'rubygems' 
require 'mechanize' 
agent = Mechanize.new 
agent.get("https://www.rottentomatoes.com/user/account/login/") do |login_page| 
    inside_page = login_page.form_with(:action => 'https://www.rottentomatoes.com/user/account/login/') do |f| 
    f.login_username = "[email protected]" 
    f.login_password = "123456" 
    end.click_button 
end 
+0

你得到了什么错误? – markthethomas

回答

0

没有你的代码的任何问题,问题是烂番茄如何处理登录,他们重定向回通过HTML主体中的JavaScript访问主页。我添加一行到您的代码(并加入我的凭据):

puts agent.page.body

结果:

<script> 
    window.top.location='http://www.rottentomatoes.com/'; 
</script> 

所以,你可以用自己的API或者,如果你想继续并执行JavaScript以遵循重定向,您可以使用WATIRSelenium