qq_30572853 2015-08-24 06:53 采纳率: 6.7%
浏览 2627

python'模拟登陆网站一直返回登陆界面

import urllib.request
import urllib.parse
import http.cookiejar

def gethtml(url):
cj = http.cookiejar.CookieJar()
cookie_jar = urllib.request.HTTPCookieProcessor(cj)
opener = urllib.request.build_opener(cookie_jar)
urllib.request.install_opener(opener)
page = urllib.request.urlopen('*******')
for index, cookie in enumerate(cj):
print ('[',index, ']',cookie)
data = {
'username':'****',
'password':'****',
'execution':'e1s1',
'lt':'LT-68105-mdbC4YmMWgjyDwVV5bI3jOWfo0FCcb-1440307068488',
'_eventId':'submit',
'rmShown':'1'
}
postdata = urllib.parse.urlencode(data).encode('utf-8')
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36',
'Referer':'******'}
req = urllib.request.Request(url,data=postdata,headers=headers)
response = urllib.request.urlopen(req)
return response.read()

def getgrade(url):
html = gethtml(url).decode('utf-8')
print(html)

if name == '__main__':
url = '******'
getgrade(url)

第一个print语句可以打印出两行cookie 第二个print html一直打印的登陆界面,求高手指教。。

  • 写回答

2条回答 默认 最新

  • threenewbee 2015-08-24 06:55
    关注

    目测你没有带上正确的cookie,具体你用fiddler看下就知道了。

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题