0

I am a python newbie and I've been trying to scrap my University's Website to get a list of my grades with no luck so far.

I try to log in making a POST request with the form-data that's shown in the code and then make a GET request for request_URL. However when I try to print the requested url's content login url's content comes up. So it is pretty clear that I can't get past login page.

import requests
from bs4 import BeautifulSoup

login_URL = 'http://gram-web.ionio.gr/unistudent/login.asp'
request_URL = 'http://gram-web.ionio.gr/unistudent/stud_CResults.asp?studPg=1&mnuid=mnu3&'

payload = {
    'userName': 'username',
    'pwd': 'password',
    'submit1': 'Login',
    'loginTrue': 'login'
}

with requests.Session() as session:
    post = session.post(login_URL, data=payload)
    r = session.get(request_URL)
    root = BeautifulSoup(r.text, "html.parser")
    print(root) 

I assume there is some kind of token value involved in the process because that's what the POST request looks like when I try to log in manually. Has anybody seen this before ? Is this the cause why I cannot log in ?

post-request

These are also the request headers.

enter image description here

Nick Garlis
  • 118
  • 9
  • Check which HTTP headers are being sent as well. I've had to set the `referer` header to do something very similar to this. – eduffy Apr 14 '18 at 12:46
  • @eduffy I've updated my post with the headers that are being sent. Do I have to set all of them ? What about the cookie ? – Nick Garlis Apr 14 '18 at 12:56
  • 1
    You are not passing the last key value pair in the form data (whatever it might be) – Keyur Potdar Apr 14 '18 at 13:04
  • @KeyurPotdar That's the thing. I have no idea what this is and each time I log in the name and the value are different – Nick Garlis Apr 14 '18 at 13:06
  • 1
    The last input field is dynamic, generated by js. If `selenium` is not an option, you can find the values (two large hex strings) in the document in the 11th ` – t.m.adam Apr 14 '18 at 21:45
  • @ t.m.adam Thank you , that solved my problem ! – Nick Garlis Apr 15 '18 at 07:56

0 Answers0