headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36",
"X-MicrosoftAjax": "Delta=true",
"X-Requested-With": "XMLHttpRequest"}
with requests.Session() as s:
url = 'https://nucleus.niituniversity.in/Default.aspx'
soup = BeautifulSoup(s.get(url).content)
login_data = {'ScriptManager1': 'SchSel$up|SchSel$btnLogin',
'__LASTFOCUS': '',
'__EVENTTARGET': '',
'__EVENTARGUMENT': '',
'__VIEWSTATE': soup.select_one("#__VIEWSTATE")["value"],
'__VIEWSTATEGENERATOR': soup.select_one("#__VIEWSTATEGENERATOR")["value"],
'SchSel$cmbUserType': 'Student',
'SchSel$txtUserName': 'user',
'SchSel$txtPassword': '1234',
'SchSel$chkSkip': 'on',
'SchSel$hidLastLogin': '2016-2017',
'SchSel$hidSchoolId': '1',
'SchSel$hidSchoolName': 'School name',
'SchSel$hidCoreUserDet': '815106',
'SchSel$hidSessionId': '8',
'SchSel$hidActiveSchool': '1',
'SchSel$hidHitCount': soup.select_one("#lblTotalHit").text.split(":", 1)[1].strip(),
'SchSel$hidReportingDet': '0',
'SchSel$hidActiveSession': '1',
'SchSel$hidSchoolAddress': 'Address',
'SchSel$hdnLoginAsUser': '',
'__ASYNCPOST': 'true',
'SchSel$btnLogin.x': '42',
'SchSel$btnLogin.y': '14'
}
s.post(url, data=login_data, headers=headers)
res = s.get('Protected page')