require 'rubygems'
require 'mechanize'
agent = Mechanize.new
page = agent.get('https://panel.dreamhost.com')
pp login_form
结果:
#<Mechanize::Form
{name nil}
{method "POST"}
{action "https://panel.dreamhost.com/index.cgi"}
{fields
[text:0x3fe74cd329bc type: text name: username value: ]
[field:0x3fe74cd32868 type: password name: password value: ]
[hidden:0x3fe74cd32714 type: hidden name: Nscmd value: Nlogin]}
{radiobuttons}
{checkboxes}
{file_uploads}
{buttons [button:0x3fe74cd2f744 type: submit name: value: ]}>
-
# Fill out and submit login form
login_form = page.form()
login_form.username = 'xxx'
login_form.password = 'xxx'
login_form.method = 'POST'
login_form.action = 'https://panel.dreamhost.com/index.cgi
page = agent.submit(login_form, login_form.buttons.first)
结果页面与原始页面相同,所以我显然做错了。任何帮助将不胜感激。
答案 0 :(得分:0)
也许提交按钮使用的是javascript而且Mechanize不会评估javascript。我几天前有一个类似的问题(使用Facebook页面),为了解决这个问题,我使用了网站的移动登录版本(https://m.facebook.com/login)......但我不认为dreamhost有一个。
有关此内容的更多信息: