I’m trying to login to a class site, but every time I submit the form I get the login page.
I have used both ways to submit the form both resulting in the same outcome. I’ve printed out the form before submitting it to check and make sure all values are filled in correctly which they were. Any suggestions on why this could be failing?
#!/home/webadmin/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
require 'rubygems'
require 'mechanize'
require 'logger'
passwd = gets.chomp
a = Mechanize.new do |agent|
agent.user_agent_alias = 'Windows Mozilla'
agent.log = Logger.new(STDOUT)
end
page = a.get('https://it210.it.et.byu.edu/accounts/login/?next=/')
puts "\n=== Login Page ==="
pp page
form = page.forms.first
form['username'] = 'user'
form['password'] = passwd
#pp form
page = a.submit(form, form.buttons.first)
#page = form.submit
puts "\n\n\n=== Next Page (should be homepage) ==="
pp page
I came across a similar problem. This worked for me