如何使用表单数据登录到websi

2024-07-04 05:26:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为我的大学创建一个应用程序,在这个应用程序中,学生必须登录才能获得他的信息数据站点发布如下参数enter image description here


发布参数的页面内容。

<input checked="checked" id="SchSel_chkSkip" name="SchSel$chkSkip" type="checkbox"/>
 <input id="SchSel_hidLastLogin" name="SchSel$hidLastLogin" type="hidden"/>
 <input id="SchSel_hidSchoolId" name="SchSel$hidSchoolId" type="hidden" value="-1"/>
 <input id="SchSel_hidSchoolName" name="SchSel$hidSchoolName" type="hidden"/>
 <input id="SchSel_hidCoreUserDet" name="SchSel$hidCoreUserDet" type="hidden"/>
 <input id="SchSel_hidSessionId" name="SchSel$hidSessionId" type="hidden" value="-1"/>
 <input id="SchSel_hidActiveSchool" name="SchSel$hidActiveSchool" type="hidden" value="-1"/>
 <input id="SchSel_hidReportingDet" name="SchSel$hidReportingDet" type="hidden" value="-1"/>
 <input id="SchSel_hidActiveSession" name="SchSel$hidActiveSession" type="hidden" value="-1"/>
 <input id="SchSel_hidHitCount" name="SchSel$hidHitCount" type="hidden" value="378284"/>
 <input id="SchSel_hidSchoolAddress" name="SchSel$hidSchoolAddress" type="hidden" value="0"/>
 <input id="SchSel_hdnLoginAsUser" name="SchSel$hdnLoginAsUser" type="hidden"/>

我知道的唯一数据是SchSel$txtsertname和SchSel$txtPassword,我可以发布它们,但如何获取其他值


我尝试的:

import requests

s = requests.Session()
url = 'https://nucleus.niituniversity.in/Default.aspx'
login_data = {'ScriptManager1' : 'SchSel$up|SchSel$btnLogin',
          '__LASTFOCUS' : '',
          '__EVENTTARGET' : '',
          '__EVENTARGUMENT' : '',
          '__VIEWSTATE' :   '/wEPDwUKMTg3OTYzNDk4Nw9kFgICAw9kFhICAQ8PFgIeB1Zpc2libGVoZGQCAg8PFgIfAGhkZAIDDwdkxvZ2luDw9kZmQaZNVi16vCv',
          '__VIEWSTATEGENERATOR' : 'CA0B0334',
          '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$hidReportingDet' : '0',
          'SchSel$hidActiveSession' : '1',
          'SchSel$hidHitCount' : '3',
          'SchSel$hidSchoolAddress' : 'Address',
          'SchSel$hdnLoginAsUser' : '',
          '__ASYNCPOST' : 'true',
          'SchSel$btnLogin.x' : '42',
          'SchSel$btnLogin.y' : '14'
            }
s.post(url,data = login_data)

res = s.get('Protected page')

但没有成功登录。为什么它是失败的,虽然我张贴所需的数据。?你知道吗


Tags: 数据nameidinputvaluetypehiddenhidschoolname

热门问题