Python模拟登录WUST教务处
2021/4/27 12:25:24
本文主要是介绍Python模拟登录WUST教务处,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Python模拟登录WUST教务处
code
import requests import json def main(): """第一次请求,获取加密的dataStr,以及cookie url1生成一段加密字符串 url2登录的界面 获取响应头的cookie, 需要注意的是响应头是一个 <class 'requests.structures.CaseInsensitiveDict'> 需要转换为字典然后取出对应的cookie """ url1 = 'http://bkjx.wust.edu.cn//Logon.do?method=logon&flag=sess' url2 = 'http://bkjx.wust.edu.cn/Logon.do?method=logon' r1 = requests.get(url1) print(r1.headers) cookie = dict(r1.headers)['Set-Cookie'] dataStr = r1.text # 按照登录页面上的JS代码进行模拟获取加密的encoded scode = dataStr.split('#')[0] sxh = dataStr.split('#')[1] username = '账号' password = '密码' code = username + '%%%' + password encode = '' i = 0 while i < len(code): if i < 20: encode += code[i:i + 1] + scode[0:int(sxh[i:i + 1])] scode = scode[int(sxh[i:i + 1]):len(scode)] else: encode += code[i:len(code)] break i += 1 print(encode) # 接下来, 请求实际的Post url data = { 'userAccount': '', 'userPassword': '', 'encoded': encode } headers = { 'Cookie': cookie } r2 = requests.post(url2, data=data, headers=headers) print(r2.text) # print(r2.url) # var scode=dataStr.split("#")[0]; # var sxh=dataStr.split("#")[1]; # var code=document.getElementById("userAccount").value+"%%%"+document.getElementById("userPassword").value; # var encoded=""; # for(var i=0;i<code.length;i++){ # if(i<20){ # encoded=encoded+code.substring(i,i+1)+scode.substring(0,parseInt(sxh.substring(i,i+1))); # scode = scode.substring(parseInt(sxh.substring(i,i+1)),scode.length); # }else{ # encoded=encoded+code.substring(i,code.length); # i=code.length; # } # } if __name__ == '__main__': main()
教务处的登录加密的方法,写在了登录界面的js中:
$.ajax( { url:strUrl, type:"post", cache:false, dataType:"text", success:function(dataStr) { if(dataStr=="no"){ return false; }else{ var scode=dataStr.split("#")[0]; var sxh=dataStr.split("#")[1]; var code=document.getElementById("userAccount").value+"%%%"+document.getElementById("userPassword").value; var encoded=""; for(var i=0;i<code.length;i++){ if(i<20){ encoded=encoded+code.substring(i,i+1)+scode.substring(0,parseInt(sxh.substring(i,i+1))); scode = scode.substring(parseInt(sxh.substring(i,i+1)),scode.length); }else{ encoded=encoded+code.substring(i,code.length); i=code.length; } } document.getElementById("encoded").value=encoded; if("logon"!="logonLdap"){ document.getElementById("userPassword").value=""; document.getElementById("userAccount").value=""; } document.getElementById("loginForm").submit(); } }, error:function() { alert("计算异常!"); } });
所以我们可以写一个类似的函数,然后得到我们需要的加密encode,同时这个界面还会返回给我们一个cookie,然后我们登录的时候只需要带着cookie和encoded
就可以实现成功登录了。
这篇关于Python模拟登录WUST教务处的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-27使用python 将ETH账户的资产打散
- 2024-09-26Python编程基础
- 2024-09-2610 种方法写出更好的 Python 代码
- 2024-09-25Python编程基础详解
- 2024-09-25Python编程入门教程
- 2024-09-25从零开始使用Python构建LLaMA 3
- 2024-09-23Python中理解和使用树形结构的简单教程
- 2024-09-23Python 编程基础入门
- 2024-09-18初探Python股票自动化交易:入门指南
- 2024-09-18Python量化入门:轻松掌握量化分析基础与实战