2015-12-22 143 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