2

I'm trying to log into our PowerSchool server through Python and Mechanize, but I can't seem to successfully do it. A tricky part of this is that the login form only has a single field for inputting both my username and password, separated by a semicolon. Here is the webpage: https://powerschool.laalliance.org/admin/home.html

Can someone tell me if my code is correct?

br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_refresh(False)
br.addheaders = [("User-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:26.0) Gecko/20100101 Firefox/26.0")]
br.open('https://powerschool.laalliance.org/admin/')

br.select_form(name='LoginForm')
br.set_all_readonly(False)
#br.find_control('pstoken').readonly = False
#br.form['pstoken'] = '123123asdfasdf123123'
br.form['password'] = 'jdoe;' + pw

br.method = 'POST'
response = br.submit()
print response.read()
Tim Dearborn
  • 1,178
  • 7
  • 18
dnaeye
  • 315
  • 1
  • 5
  • 12

1 Answers1

1

Checked the website, and if you do right-click on the form, then 'inspect element' you will see that the name of the form is : "password"

Hence, you should replace your line:

br.select_form(name='LoginForm')

to

br.select_form(name='password')

Does that solve your problem?

I want badges
  • 6,155
  • 5
  • 23
  • 38
  • Actually, just tried your original code, and I get the following among other things: "Invalid Username or Password! Attempt has been recorded." Looks like it should be working, since I got no password and that is why my login attempt fails. – I want badges Jan 23 '14 at 23:08
  • 1
    Oh, I hadn't thought to look for an error message. Once I saw that the page returned was a robots page, I just assumed the login failed. I guess now I have to figure out how to avoid being detected as a robot. Thanks for that tip, I Want Badges (lol your name). – dnaeye Jan 24 '14 at 15:45