2017-02-19 203 views
2

我正在尝试使用Mechanize在亚马逊上登录我的Kindle帐户。使用Mechanize登录到https://kindle.amazon.com/login

登录页面URL是https://kindle.amazon.com/login

我可以手动登录到该页面没有问题,但如果我尝试使用下面的代码它总是失败,错误(见下图)。

require 'mechanize' 

mechanize_agent      = Mechanize.new 
mechanize_agent.user_agent_alias  = 'Windows Mozilla' 

signin_page   = mechanize_agent.get("https://kindle.amazon.com/login") 
signin_form   = signin_page.form("signIn") 
signin_form.email  = "[email protected]" 
signin_form.password = "password" 
post_signin_page  = mechanize_agent.submit(signin_form) 

这始终是结果页面(再次,我敢肯定,我的剧本是使用有效值):

enter image description here

回答

2

看起来机械化试图提交表单没有propper行动。尝试使用继续按钮,与该按钮将表格:

# ... 
submit_button = signin_form.buttons.find { |b| b.value == "Continue" } 
post_signin_page = mechanize_agent.submit signin_form, submit_button 
+0

不幸的是,结果都是一样的。我真的不明白这里发生了什么。 – RobertJoseph

+1

我会尝试在几个小时内再次调试它。你能告诉我你使用什么版本的机械化? – Wikiti

+0

非常感谢。从'宝石列表':'机械化(2.7.5,2.7.4)' – RobertJoseph