学习通--超星自动签到(Python)
1 import requests 2 import json 3 import time 4 5 #填入Cookie 6 headers={ 7 "Cookie": "", 8 "User-Agent": "" 9 } 10 #填入uid 11 uid="" 12 coursedata=[] 13 activeList=[] 14 course_index=0 15 speed=10 16 status=0 17 status2=0 18 activates=[] 19 def backclazzdata(): 20 global coursedata 21 url="http://mooc1-api.chaoxing.com/mycourse/backclazzdata?view=json&rss=1" 22 res=requests.get(url,headers=headers) 23 cdata=json.loads(res.text) 24 if(cdata['result']!=1): 25 print("请补充Cookie否则课程列表获取失败") 26 return 0 27 for item in cdata['channelList']: 28 if("course" not in item['content']): 29 continue 30 pushdata={} 31 pushdata['courseid']=item['content']['course']['data'][0]['id'] 32 pushdata['name']=item['content']['course']['data'][0]['name'] 33 pushdata['imageurl']=item['content']['course']['data'][0]['imageurl'] 34 pushdata['classid']=item['content']['id'] 35 coursedata.append(pushdata) 36 print("获取成功") 37 #print(coursedata) 38 printdata() 39 40 def printdata(): 41 global course_index,speed 42 index=1 43 for item in coursedata: 44 print(str(index)+".课程名称:"+item['name']) 45 index+=1 46 course_index=int(input("请输入监控课程监控课程序号:"))-1 47 print("监控课程设定完成") 48 speed=int(input("请输入监控频率:")) #频率是监控的速度,一格10秒,适中选择就好 49 print("监控频率设置完毕") 50 res=input("输入start启动监控:") 51 if(res=="start"): 52 startsign() 53 else: 54 printdata 55 56 def taskactivelist(courseId,classId): 57 global activeList 58 url="https://mobilelearn.chaoxing.com/ppt/activeAPI/taskactivelist?courseId="+str(courseId)+"&classId="+str(classId)+"&uid="+uid 59 res=requests.get(url,headers=headers) 60 data=json.loads(res.text) 61 activeList=data['activeList'] 62 #print(activeList) 63 for item in activeList: 64 if("nameTwo" not in item): 65 continue 66 if(item['activeType']==2 and item['status']==1): 67 signurl=item['url'] 68 aid = getvar(signurl) 69 if(aid not in activates): 70 print("【签到】查询到待签到活动 活动名称:%s 活动状态:%s 活动时间:%s aid:%s"%(item['nameOne'],item['nameTwo'],item['nameFour'],aid)) 71 sign(aid,uid) 72 73 def getvar(url): 74 var1 = url.split("&") 75 for var in var1: 76 var2 = var.split("=") 77 if(var2[0]=="activePrimaryId"): 78 return var2[1] 79 return "ccc" 80 81 82 83 def sign(aid,uid): 84 global status,activates 85 url="https://mobilelearn.chaoxing.com/pptSign/stuSignajax?activeId="+aid+"&uid="+uid+"&clientip=&latitude=-1&longitude=-1&appType=15&fid=0" 86 res=requests.get(url,headers=headers) 87 if(res.text=="success"): 88 print("用户:"+uid+" 签到成功!") 89 activates.append(aid) 90 status=2 91 else: 92 print("签到失败") 93 activates.append(aid) 94 95 def startsign(): 96 global status,status2 97 status=1 98 status2=1 99 ind=1 100 print("监控启动 监控课程为:%s 监控频率为:%s"%(coursedata[course_index]['name'],str(speed))) 101 while(status!=0 and status2!=0): 102 ind+=1 103 taskactivelist(coursedata[course_index]['courseid'],coursedata[course_index]['classid']) 104 time.sleep(speed) 105 if(status==1): 106 print(str(ind)+" [签到]监控运行中,未查询到签到活动") 107 elif(status==2): 108 print(str(ind)+" [新签到]监控运行中,未查询到签到活动") 109 print("任务结束") 110 printdata() 111 112 backclazzdata()
每个人的cookie都不一样的,所以劳烦自行到浏览器检索网页,查询自己的cookie,将其填入!!!
注意:目前这个只能监控一个科目,可以多开几个这个脚本,分别挂着就行了。
诚者,君子之所守也。