Python爬内蒙古大学教务处并自动计算绩点(小窗体版)

xiaoxiao2021-02-27  225

直接上代码(可参考以前爬ecust的备注)

from tkinter import * from time import ctime import requests as rq from pyquery import PyQuery as pq def gpa(i):#定义绩点 if i=="优": return 3.7 if i=='合格': return 1.0 i=float(i) if i>=90 and i<=100: return 4.0 elif i<=89 and i>=85: return 3.7 elif i<=84 and i>=82: return 3.3 elif i<=81 and i>=78: return 3.0 elif i<=77 and i>=75: return 2.7 elif i<=74 and i>=71: return 2.3 elif i<=70 and i>=66: return 2.0 elif i<=65 and i>62: return 1.7 elif i<=61 and i>=60: return 1.3 elif i<=59 and i>=0: return 0 def cal(L): sum1=0#学分 sum2=0#学分*绩点 for eachline in L: if '选修' not in eachline[2] or '体育' in eachline[0]: sum1=sum1+float(eachline[1]) sum2=sum2+float(eachline[1])*gpa(eachline[3]) return sum2/sum1 def main(username='',password=''): urls=["http://jwxt.imu.edu.cn/loginAction.do","http://jwxt.imu.edu.cn/gradeLnAllAction.do?type=ln&oper=fainfo&fajhh=33416",username,password] H={"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding":"gzip, deflate", "Accept-Language":"zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4", "Cache-Control":"max-age=0", "Connection":"keep-alive", "Content-Length":"30", "Content-Type":"application/x-www-form-urlencoded", "Host":"jwxt.imu.edu.cn", "Origin":"http://jwxt.imu.edu.cn", "Referer":"http://jwxt.imu.edu.cn/loginAction.do", "Upgrade-Insecure-Requests":"1", "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"} L0=[] L1=[] s=rq.session() data0={'zjh':urls[2],'mm':urls[3]} s.post(urls[0],data=data0,headers=H) pages=s.get(urls[1]).text doc=pq(pages) j=doc('table').filter('#user').find('td') for i in j: L0.append(pq(i).text()) Lj=len(L0) #for i in range(0,int(Lj/8)): # L1.append([L0[8*i],L0[8*i+1],L0[8*i+2],L0[8*i+3],L0[8*i+4],L0[8*i+5],L0[8*i+6],L0[8*i+7]]) #返回n*8维 每一列和教务处对应 for i in range(0,int(Lj/8)): L1.append([L0[8*i+2],L0[8*i+4],L0[8*i+5],L0[8*i+6]]) #返回n*4 名 学分 属性 分数 return L1 def insert2(): T1.delete(0.0,END) T1.insert(1.0,"%s请耐心等待...."%ctime()) username=E1.get() password=E2.get() L1=main(username,password) pages='\n' for eachline in L1: for items in eachline: pages=pages+items+' ' pages+='\n您的全部成绩如下:\n' gpa=cal(L1)#计算绩点 T1.delete(0.0,END) T1.insert(1.0,"您的必修课绩点是%s"%gpa) T1.insert(2.0,pages) root=Tk() root.geometry("1000x700") root.title("内蒙古大学JWC成绩爬取") L1=Label(root,text="用户名") L2=Label(root,text="密码") L3=Label(root,text="作者:华理小司机@华东理工大学");L3.place(relx=0.8,rely=0.1); B1=Button(root,text="确定",command=insert2) E1=Entry(root) E2=Entry(root,show='*') T1=Text(root,width=800,height=1000) L1.pack();E1.pack();L2.pack();E2.pack();B1.pack();T1.pack() root.mainloop()
转载请注明原文地址: https://www.6miu.com/read-12466.html

最新回复(0)