使用python执行登录脚本以登录.asp网站

时间:2016-04-15 09:14:45

标签: python html login

我正在尝试编写一个能够在此网站中执行登录的脚本:https://du.ilsole24ore.com/utenti/Login.aspx?RURL=http%3a%2f%2fwww.banchedati.ilsole24ore.com%2fenter.do%3fproduct%3dBIG&errurl=http%3a%2f%2fwww.banchedati.ilsole24ore.com%2f&sitecode=BR

我已经看过已经在互联网上提供的各种解决方案,但我没有让它们正常工作。

html源代码如下

<body>



<header id="header">
            <div class="container">
                <div class="row-fluid">
                    <div class="span3">
                        <a href="http://www.ilsole24ore.com" id="logo" class="thumbnail">
                            <img src="img/logo_sole24_new.png" />
                        </a>
                    </div>
                </div>
            </div>
        </header>
    <div id="content">
        <div class="container">
            <div class="well well-sha">
                <div class="well">
                </div>
                <span class="separator"></span>

                <form class="form-block" id="AuthUser" method="post" action="/DU/AuthFiles/LoginCentrale.aspx" onsubmit="return ValidateForm();">

                    <input id="SC" type="hidden" value='BR' name="SC"/>
                    <input id="RURL" type="hidden" value="http://www.banchedati.ilsole24ore.com/enter.do?product=BIG" name="RURL"/> 
                    <input id="ERRURL" type="hidden" value='/Utenti/login.aspx?RURL=http%3a%2f%2fwww.banchedati.ilsole24ore.com%2fenter.do%3fproduct%3dBIG&amp;SiteCode=BR' name="ERRURL"/>



                     <fieldset class="form_h" style=" padding-bottom:0px!important; border-bottom:0px!important; margin-bottom:0px!important;">



                        <div class="row-fluid">
                            <div class="span6  offset2">
                                <div class="row-fluid">
                                    <div class="span4">
                                        <label class="" for="username">Username / Email</label>
                                    </div>
                                    <div class="span8">
                                        <div class="validation ">
                                            <input value="" name="txtUsername" id="txtUserName" type="text"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="row-fluid">
                            <div class="span6 offset2 ">
                                <div class="row-fluid">
                                    <div class="span4">
                                        <label class="" for="password">Password</label>
                                    </div>
                                    <div class="span8">
                                        <div class="validation ">
                                            <input value="" id="txtPassword" name="txtPassword" type="password" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="row-fluid">
                            <div class="span6  offset2">
                                <div class="row-fluid">
                                    <div class="span4">
                                        <label class="" ></label>
                                    </div>
                                    <div class="span8">
                                        <div class="validation ">

                                            <span class="btn">
                                                <input type="checkbox" name="RememberMe" id="RememberMe" class="checkRemember" value="1" />
                                                Rimani collegato
                                            </span>

                                             <button type="submit" class="btn btn-sole">
                                    ACCEDI 
                                </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="row-fluid">
                            <div class="span6  offset2">
                                <div class="row-fluid">
                                    <div class="span4">
                                        <label class="" ></label>
                                    </div>
                                    <div class="span8">
                                        <div class="validation ">
                                            <a id="linkPasswordReminder" href="passwordReminder.aspx">Recupera password</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>


                     </fieldset>



                </form>

                <span class="separator"></span>

                <div class="well">
                    <h4>Nuovo Utente?</h4>
                    <p>Segui passo dopo passo le indicazioni che ti saranno fornite, fino a che non ti verrà restituito sullo schermo il messaggio "Registrazione effettuata con successo".<br />
        Da utente registrato potrai ritrovare le informazioni da te rilasciate, all'interno della tua scheda personale ("<a href="/Utenti/areautente/ilmioprofilo.aspx?SiteCode=BR&amp;RURL=http%3a%2f%2fwww.banchedati.ilsole24ore.com%2fenter.do%3fproduct%3dBIG">Il mio 
                                                    profilo</a>").</p>
                    <p><a style="text-decoration:underline" href='/Utenti/Registrazione.aspx?SiteCode=BR&amp;RURL=http%3a%2f%2fwww.banchedati.ilsole24ore.com%2fenter.do%3fproduct%3dBIG&amp;ERRURL=http%3a%2f%2fwww.banchedati.ilsole24ore.com%2f'>Registrati adesso</a></p>
                </div>


            </div>
        </div>
    </div>      
      </div>
    </footer>

 </body>


</html>

到目前为止,我已编写了这段代码,但它并没有给我正确的值:我应该在登录后读取Cookie中的一些值:

import requests
import cookielib


jar = cookielib.CookieJar()
login_url = 'https://du.ilsole24ore.com/utenti/Login.aspx?RURL=http%3a%2f%2fwww.banchedati.ilsole24ore.com%2fenter.do%3fproduct%3dBIG&errurl=http%3a%2f%2fwww.banchedati.ilsole24ore.com%2f&sitecode=BR'
acc_pwd = { 'SC':'BR',
            'txtUsername':'username',
            'txtPassword':'password',
            'RURL':'http://www.banchedati.ilsole24ore.com/enter.do?product=BIG',
            'ERRURL':'/Utenti/login.aspx?RURL=http%3a%2f%2fwww.banchedati.ilsole24ore.com%2fenter.do%3fproduct%3dBIG&amp;SiteCode=BR'
          }

r = requests.get(login_url, cookies=jar)
r = requests.post(login_url, cookies=jar, data=acc_pwd)

print r
print r.cookies

我得到的输出是:

<Response [200]>
<RequestsCookieJar[]>

错误在哪里? 感谢

0 个答案:

没有答案