str = input("请输入:"); #将输入内容存入字符串
print ("你输入的内容是: ", str)
requests登陆正方教务管理系统
####requests登录教育网
import requests
class Mju:
def __init__(self):
self.headers = {
"Host": "jwgl.mju.edu.cn",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"}
self.url = "http://jwgl.mju.edu.cn/" #学校教务管理官网
self.session = requests.session()
def get_cookies(self): #从首页拿到cookies,因为就两个,所以不写太麻烦了
base_response = self.session.get(self.url,headers = self.headers)
cookies = base_response.cookies
self.cookie_dict1 = {}
self.cookie_dict1["ASP.NET_SessionId"] = cookies['ASP.NET_SessionId']
self.cookie_dict1["ASP.NET_SessionId_NS_Sig"] = cookies['ASP.NET_SessionId_NS_Sig']
return self.cookie_dict1
def checkcode(self): #手写验证码,当然你也可以做个深度学习识别二维码或者买识别二维码的
self.response = self.session.get(self.url, headers=self.headers)
checkcode_url = "http://jwgl.mju.edu.cn/CheckCode.aspx"
response1 = self.session.get(checkcode_url,headers = self.headers,cookies=self.cookie_dict1)
img = response1.content
with open ("checkcode.jpg","wb") as f: #二进制写入
f.write(img)
f.close()
def login(self,login_name,login_password,login_code):
formdata = {'__VIEWSTATE': 'dDwxNTMxMDk5Mzc0Ozs+3nz05h+XSFTZzEfxTy/80dBgOck=', #####表单数据都放在 default2.aspx 文件中,__VIEWSTATE 每个人的都不一样,但是是固定的,直接拿下来就好,
'txtUserName': login_name, #一定一定要全拿下来,空的也拿下来
'Textbox1':'',
'TextBox2': login_password,
'txtSecretCode': login_code,
'RadioButtonList1': '%D1%A7%C9%FA',
'Button1':'',
'lbLanguage':'',
'hidPdrs':'',
'hidsc':'',
}
login_url = "http://jwgl.mju.edu.cn/default2.aspx"
response_login = self.session.post(login_url, headers=self.headers,data=formdata)
response_login.encoding = "gbk"
##网站的charset是gb2312,但是我名字他不会写所以就用gbk了
info_url = "http://jwgl.mju.edu.cn/xs_main.aspx?xh="+login_name
response_stu = self.session.get(info_url,headers = self.headers,cookies = self.cookie_dict1)
function(){ //外汇返佣 http://www.fx61.com/
response_stu.encoding = "gbk"
print(response_stu.text)
if __name__ == "__main__":
t = Mju()
t.get_cookies()
t.checkcode()
login_name = input(str("请输入学号:"))
login_password = input(str("请输入密码:"))
login_code = input(str("请输入验证码:")) #打开 checkcode.jpg 输入验证码
t.login(login_name,login_password,login_code) |
|