0

robobrowser を使用して Web サイトでのログイン プロセスを自動化しようとしています。コードは次のとおりです。

browser = RoboBrowser()
login_url = 'https://fiitjeelogin.com'
post_login = 'https://fiitjeelogin.com/StudentDashboard.aspx?UserdID=1110611570024&BatchCode=MDIT57T04,%20MDIT57F05,%20MDIT57R05&CenterCode=61'

eventval = '/wEdAAl1eLz1ChyMlpOH84l9DXRBKhoCyVdJtLIis5AgYZ/RYe4sciJO3Hoc68xTFtZGQEg/Lx6HO3zp5MHCG49Y5hGYd39wMEiroGigGt6l+80X6qoJzVbh9uRjatIO8j62gEVUrsGtEC0SKq72cYUQj6MH2BaA8epCgZlCbUaqFyjHLgdkZW6ckU2fp2bSHM106Q/CZwerK9DhufKPKISNnwtBsTsTMrfob//+ZrYm6E/+LQ=='

viewstat = '/wEPDwUJOTI4MjgwNjQwD2QWAgIDD2QWAgIPD2QWAgIBD2QWAmYPZBYGAgMPFgIeB1Zpc2libGVoZAILDxYCHwBoZAINDw8WAh4EVGV4dAUEU2VuZGRkZFRRYynlwFTooznce3Y+ZTEmDUGkCBVmcuPXOfi78tSc'


browser.open(login_url)
form = browser.get_form(id = 'ctl01') #choosing matching form id
form['username'].value = 'username'
form['password'].value = 'password'
form['__VIEWSTATEGENERATOR'].value = 'C8125695' #constant
form['__EVENTVALIDATION'].value = eventval
form['__VIEWSTATE'] = viewstat
form['txtUsername'] = ''
form['txtemailid'] = ''

b_e_arg = '\<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" \/\>'

a = robobrowser.forms.fields.Input(b_e_arg) #assigning this using form['__EVENTARGUMENT'] gave a 400 BAD REQUEST...same for EVENTTARGET

b_e_target = '\<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" \/\>'

b = robobrowser.forms.fields.Input(b_e_target)
form.add_field(a)
form.add_field(b)
b_e_btn = '\<input class="buttonb" id="btnlogin" name="btnlogin" type="submit" value="Log in"\/\>'
c = robobrowser.forms.fields.Input(b_e_btn)
form.add_field(c)
submit_here = form['btnlogin']
submit_here.value = 'Log+in'
browser.submit_form(form, submit = submit_here)
alltext = browser.parsed
print alltext

現在、ログイン フォームは、Firefox のデバッグで見られるように、次の入力を受け取ります。

__EVENTTARGET、__EVENTARGUMENT、__VIEWSTATE、__VIEWSTATEGENERATOR、__EVENTVALIDATION、ユーザー名、パスワード、btnlogin、txtUsername、txtemailid、

__VIEWSTATEGENERATOR 、 __EVENTVALIDATION 、 __VIEWSTATE の値は変更されません。

コードはログインページの HTML を返しますが、ログイン後のページの HTML が必要です。

私はこれとこれから試しました

ログインページの HTML は次のとおりです。

<body>
    <form method="post" action="" id="ctl01">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJOTI4MjgwNjQwD2QWAgIDD2QWAgIPD2QWAgIBD2QWAmYPZBYGAgMPFgIeB1Zpc2libGVoZAILDxYCHwBoZAINDw8WAh4EVGV4dAUEU2VuZGRkZFRRYynlwFTooznce3Y+ZTEmDUGkCBVmcuPXOfi78tSc" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['ctl01'];
if (!theForm) {
    theForm = document.ctl01;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

<div class="aspNetHidden">

    <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="C8125695" />
    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAl1eLz1ChyMlpOH84l9DXRBKhoCyVdJtLIis5AgYZ/RYe4sciJO3Hoc68xTFtZGQEg/Lx6HO3zp5MHCG49Y5hGYd39wMEiroGigGt6l+80X6qoJzVbh9uRjatIO8j62gEVUrsGtEC0SKq72cYUQj6MH2BaA8epCgZlCbUaqFyjHLgdkZW6ckU2fp2bSHM106Q/CZwerK9DhufKPKISNnwtBsTsTMrfob//+ZrYm6E/+LQ==" />
</div>
        <fieldset style="border-color: #95B3d7; border-bottom: 0px; border-right: 0px; border-top: 0px;
            border-left: 0px; padding-left: 10px">
            <legend style="color: #365f91; font-weight: bold; font-family: Calibri; font-size: 15px">
                Already Registered</legend>
            <p>
                <img src="StartpageImage/LoginLock.png" style="width: 130px; height: 130px" />
            </p>
            <div class="row">
                <section class="col col-8">
              <label class="label" style="color:#3698db ;font-family:Calibri">User Name</label><br />
              <label class="input"> 

                <input name="username" type="text" id="username" class="Jaitextbox" />
              </label>
            </section>
                <section class="col col-8">
              <label class="label" style="color:#3698db ;font-family:Calibri">Password</label><br />
              <label class="input"> 

                <input name="password" type="password" id="password" class="Jaitextbox" />
              </label><br />


              <p align="right" style="margin-right:100px;"><a id="lnkforgetpassword" href="javascript:__doPostBack(&#39;lnkforgetpassword&#39;,&#39;&#39;)" style="color:#F79646;color:#f79646 ;font-family:Calibri">Forgot Password?</a></p>
            </section>
            </div>
            <input type="submit" name="btnlogin" value="Log in" id="btnlogin" class="buttonb" />
    </div>

<div class="body">
            <div id="updatpanelforgetpass">


                    <table>
                        <tr id="trDisp1">
            <td colspan="2">
                                <h3 align="center" style="color: #365f91; font-family: Calibri; font-weight: bold">
                                    <u>Forgot Password</u></h3>
                            </td>
        </tr>


                        <tr id="trDisp3">
            <td colspan="2">
                                Please provide registered User Name or EmailId with Fittjee
                            </td>
        </tr>

                        <tr id="trDisp4">
            <td>
                                <span id="lblUsername" style="color: #3698db; font-family: Calibri">UserName :</span>
                            </td>
            <td>
                                <input name="txtUsername" type="text" id="txtUsername" class="Jaitextbox" /></p> 
                            </td>
        </tr>

                        <tr id="trDisp5">
            <td>
                                <span id="lblemailid" style="color: #3698db; font-family: Calibri">EmailID :</span>&nbsp;&nbsp;&nbsp;&nbsp;
                            </td>
            <td>
                                <input name="txtemailid" type="text" id="txtemailid" class="Jaitextbox" />
                            </td>
        </tr>


                        <tr>
                            <td colspan="2">
                                <input type="submit" name="btnPass" value="Send" id="btnPass" class="buttonb" />
                            </td>
                            <div id="ValidationSummary1" class="error" style="display:none;">

        </div>
                            <span id="lblMessage" style="color:Red;"></span>
                        </tr>
                    </table>

    </div>

        </div>

</div>
4

0 に答える 0