python用户界面登录错误_python模拟登陆失败,一直跳回登陆页面

# 导入模块 urllib2

import urllib

import urllib2

import cookielib

from bs4 import BeautifulSoup

import re

import sys;

reload(sys);

sys.setdefaultencoding('utf8');

login_url='http://***/cas/login?service=http%3A%2F%2F***%2Fmamplatform%2Flogon.action'

url = 'http://***/mamplatform/index.action'

html1=urllib2.urlopen(login_url).read()

soup1=BeautifulSoup(html1)

lt=soup1.select("[name=lt]")[0]["value"]

execution=soup1.select("[name=execution]")[0]["value"]

cj=cookielib.CookieJar()

opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj),urllib2.HTTPHandler)

urllib2.install_opener(opener)

h=urllib2.urlopen(url).read()

headers = {

'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)',

'Accept': 'application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*',

'Connection': 'keep-alive',

'Referer':'http://***/cas/login?service=http%3A%2F%2F***%2Fmamplatform' }

postData=urllib.urlencode({

'username':'aa',

'password':'aa',

'password-prompt':'请输入密码',

'lt':lt,

'execution':execution,

'_eventId':'submit'

})

print postData

req = urllib2.Request(login_url, postData,headers=headers)

response = opener.open( req )

print response.info()

doc = response.read()

req2 = urllib2.Request(url)

response2 = opener.open( req2 )

print response2.info()

doc2 = response2.read()

print 'old url:'+url

print 'real url:'+response2.geturl()

代码如上所示,不知哪里有问题,一直在登陆界面,通过HTTPWATCH抓包如下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值