1
require 'rubygems'
require 'mechanize'

agent = Mechanize.new

page = agent.get('https://panel.dreamhost.com')

pp login_form

results in:

#<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)

The resulting page is the same as the original page so I am obviously doing something wrong. Any help would be much appreciated.

RobertJoseph
  • 7,968
  • 12
  • 68
  • 113
  • 1
    I looked at it and the form looks straightforward. Check your username and password, also there may be an error message in the response, finally you shouldn't need to set method or action. – pguardiario Sep 12 '15 at 22:18

1 Answers1

0

Maybe that submit button is using javascript and Mechanize does not evaluate javascript. I had a similar problem a few days ago (using Facebook page), to solve that, I used an mobile login version of the website (https://m.facebook.com/login)... But I don't think dreamhost has one.

For more information about this:

Community
  • 1
  • 1
soltex
  • 2,993
  • 1
  • 18
  • 29