通过urllib

时间:2016-07-07 01:41:09

标签: python login urllib2

登录表格如下:



<form action="/idp/profile/SAML2/Redirect/SSO?execution=e1s1" method="post" name="loginForm">
    <div class="form-element-wrapper">
        <label for="username">Username</label>
        <input autocapitalize="off" autofocus="" class="round" id="username" name="j_username" placeholder="GatorLink Username" type="text" value="">
    </div>
    <div class="form-element-wrapper">
        <label for="password">Password</label>
        <input autocapitalize="off" class="round" id="password" name="j_password" placeholder="Password" type="password" value="">
    </div>
    <div class="form-element-wrapper">
        <input type="hidden" name="donotcache" value="0">
    </div>
    <div class="form-element-wrapper">
        <input id="_shib_idp_revokeConsent" type="hidden" name="_shib_idp_revokeConsent" value="false">
    </div>
    <div class="form-element-wrapper">
        <button class="round" type="submit" name="_eventId_proceed">Login</button>
    </div>
</form>
&#13;
&#13;
&#13;

简单的代码如下:

import urllib
import urllib2
username = "xxx"
password = "xxx"
url = 'https://login.xxx.edu/idp/profile/SAML2/Redirect/SSO?execution=e1s1'
values = { 'j_username': username,'j_password': password }
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
result = response.read()
print result

导致

  

HTTPError:错误请求

我应该提供其他数据让它登录吗?谁能解释一下如何一步一步地做到这一点?

0 个答案:

没有答案