1

I'm trying to login to PowerSchool to scrape my grades. Whenever I run the code it gives me the login pages HTML code instead of the secured pages HTML code.

Question 1: How do I get the value of the 3 fields that change labeled 'this changes' in the code above, and submit it to the current post?

Question 2: Am I required to add anything in the code for my password that gets hashed each post.

https://ps.lphs.net/public/home.html <--- Link to login page for HTML code.

Picture of form data on chrome

import requests


payload = {
    'pstoken': 'this changes',
    'contextData': 'this changes',
    'dbpw': 'this changes',
    'translator_username': '',
    'translator_password': '',
    'translator_ldappassword': '',
    'serviceName':' PS Parent Portal',
    'serviceTicket':'',
    'pcasServerUrl':' /',
    'credentialType':'User Id and Password Credential',
    'account':'200276',
    'pw':'my password',
    'translatorpw':''
}

head = {'User-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3180.0 Safari/537.36'}

with requests.Session() as s:
    p = s.post('https://ps.lphs.net/public/', data=payload, headers=head)

    r = s.get('https://ps.lphs.net/guardian/home.html')
    print(r.text)

EDIT 1 :

    s.headers = {
        'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3180.0 Safari/537.36'}

    p = s.get('https://ps.lphs.net/guardian/home.html')
    print(p.text)

    r = s.post('https://ps.lphs.net/guardian/home.html', data=payload,
               headers={'Content-Type': 'application/x-www-form-urlencoded',
                        'Referer': 'https://ps.lphs.net/public/home.html'})

    print(r.text)

1 Answers1

0

Give this a shot. It should fetch you the valid response:

import requests

payload = {
    'pstoken': 'this changes',
    'contextData': 'this changes',
    'dbpw': 'this changes',
    'translator_username': '',
    'translator_password': '',
    'translator_ldappassword': '',
    'serviceName':' PS Parent Portal',
    'serviceTicket':'',
    'pcasServerUrl':' /',
    'credentialType':'User Id and Password Credential',
    'account':'200276',
    'pw':'my password',
    'translatorpw':''
}

with requests.Session() as s:
    s.headers={'User-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3180.0 Safari/537.36'}
    r = s.post('https://ps.lphs.net/guardian/home.html',data=payload,
                headers={'Content-Type': 'application/x-www-form-urlencoded',
                        'Referer':'https://ps.lphs.net/public/home.html'})
    print(r.text)

Btw, change the parameter in payload (if needed) to get logged in.

SIM
  • 21,997
  • 5
  • 37
  • 109
  • It didn't work, but I think its because the pstoken, contextData, and dbpw fields change each session. So how would I go about getting those fields and changing payload before I call the payload variable? – Sam Scolari Oct 24 '17 at 00:17
  • I started using the p var to try to parse the page to get the contextData and pstoken so I could put it in the payload before posting. When I printed p and r I ended up getting different strings for the fields. The code is shown above in EDIT 1 : – Sam Scolari Oct 24 '17 at 00:24