Python login to javascript form site

I try to enter my school site using Requests, but it does not go past the login page and does not return data on password-protected pages. All he does is return the HTML login page. Twill will not work, since javascript is required on this page., Material for entering HTML:

<!--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 checked this answer

My current code

 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 access the page. My question is: do I suppose I have a payload to click the send button or something else? I tried 'action' : 'login' and all that, but none of this works. Also, I don't need translatorpw , so should I write 'translatorpw': '' or just ignore it? 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.

+5
source share
1 answer

Try customizing your headers, as some sites reject the request by default.

  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 sent with your mail requests, if they also send it to the payload.

0
source

Source: https://habr.com/ru/post/1236392/


All Articles