dlpnewbie96 dlpnewbie96 - 3 years ago 115
Python Question

Python script to login into website not working

This is my code:

from requests import session

payload = {
'action': 'login',
'TB1$TabPanel1$txt_user_name': '2016XXXXXXXXX',
'TB1$TabPanel1$txt_password': '6XXXXXXXX'

with session() as c:
c.post('http://erp.sangamuniversity.ac.in/Default.aspx', data=payload)
response = c.get('http://erp.sangamuniversity.ac.in/Student/Student_Home.aspx')
print response.text

statement is printing the html source of the login page (http://erp.sangamuniversity.ac.in/Default.aspx) instead of the homepage after login (http://erp.sangamuniversity.ac.in/Student/Student_Home.aspx'). Why? (The actual username and password is being provided for testing the script).

2ps 2ps
Answer Source

It looks like the Default.aspx page is actually posting to default1.aspx.

<form id="Form1" method="post" action="default1.aspx" onsubmit="javascript:return WebForm_OnSubmit();">

You should update your script to post to default1.aspx and not Default.aspx.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download