7

I'm attempting to log into my school's website using Requests, but it doesn't get past the log in page and doesn't return the stuff in the password protected pages. All it does is return the HTML of the login page. Twill would not work as this page requires javascript. . The HTML login stuff is

<!--box content-->

<div id="noscript" class="feedback-alert"> To sign in to PowerSchool, you must use a browser that supports and has JavaScript enabled. </div>
<fieldset id="login-inputs" class="hide">

    <div>
          <label>Username</label>
          <input type="text" id="fieldAccount" name="account" value="" size="39"  />
    </div>
    <div>
          <label>Password</label>
          <input type="password" name="pw" value="" size="39"  /><div id="login-help"><a href="/public/account_recovery_begin.html">Having trouble signing in?</a></div>
    </div>
    <div id="translatorInput">
          <label>Translator Sign In</label>
          <input type="password" name="translatorpw" value="" size="39"  />
    </div>
    <div class="button-row">
    <button type="submit" id="btn-enter" title="Sign In To PowerSchool Parent Access" value="Enter" border="0" >Sign In</button>
    </div>
</fieldset> 

  <!-- box content-->

I've checked this answer

My current code is

import requests
payload = {
    'account': 'username',
    'pw': 'password'
}
with requests.Session() as s:
    p = s.post('https://powerschool.-/public/home.html', data=payload)   
    print p.text

    r = s.get('https://powerschool.-/guardian/studentsched.html')
    print r.text

but I can't seem to log into the page. My question is am I suppose to have a payload to press the 'submit' button or something? I've tried 'action' : 'login' and stuff like that but none of it works. Also, I don't need a translatorpw so should I write 'translatorpw': '' or just ignore that? Obviously I put my real username/password in the program on my laptop. Thanks in advance!

Edit: I just used Selenium and it worked very easily.

Community
  • 1
  • 1
bolkols
  • 71
  • 1
  • 4
  • I'm not sure but your program might have to act even more like a browser. You will have to examine the page, examine all the fields of `p`, and attempt to find out what the server expects. There is javascript code on the page with comments about POST requests. You'll have to take all of that into consideration. – RobertL Nov 20 '15 at 03:51
  • Yes, I looked in the HTML returned by my code and it doesn't have anything that looks like the one in the other page, so I'm confused about that too. – bolkols Nov 20 '15 at 04:14

1 Answers1

1

Try setting up custom headers as some sites reject default requests agent

    import requests

     payload = {
    'account': 'username',
    'pw': 'password'
     }

     headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0'}     

with requests.Session() as s:
    p = s.post('https://powerschool.-/public/home.html', data=payload, headers=headers)   
    print p.text

    r = s.get('https://powerschool.-/guardian/studentsched.html', headers=headers)
    print r.text

Check if there are any additional parameters that are being send with your post requests, if so send it in payload too.

rikoudosenin
  • 91
  • 2
  • 11