无法使用mechanize登录rottentomatoes.com

时间:2015-12-22 05:04:26

标签: ruby mechanize-ruby

我使用以下代码: -

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 = "random@mailinator.com"
    f.login_password = "123456"
  end.click_button
end

1 个答案:

答案 0 :(得分:0)

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

puts agent.page.body

结果:

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

因此,您可以使用他们的API,或者如果您想继续并执行JavaScript以遵循您可以使用WATIRSelenium的重定向。