南通大学自动评教脚本(python)

来源:互联网 发布:mac上装windows虚拟机 编辑:程序博客网 时间:2024/05/03 06:54

       临近期末我等学沫都在紧张的进行着复习(预习),本来时间就不多,居然还让我们去评教万一因为这点时间我们挂科了咋办,于是乎用半生不熟的python写个自动评教的脚本。

一,具体分析:

我们先来评一个抓包来看

1.可以看出

请求方法:POST

地址 : /cjcx/actions/SubmitEvaluationTeaching.aspx

参数 :

cjid:是课程编号

cpjg: 是评级 

advice: 是建议

2.来找获得cjid的请求

可以看出

请求方法:post(经测试,get同样有效)

地址:/cjcx/Data/EvaluationCourseData.aspx

没有参数

二,具体流程

1.模拟登陆(之前的文章写过了这里)

2.请求cjid,用正则表达式来找出cjid

3.遍历cjid,构造求参数,向提交地址提交

4.处理请求的返回,判断评教成功与否


三,效果




四,完整代码

#!/usr/bin/env python# -*- coding:utf-8 -*-import urllib2import urllibimport cookielibimport recj=cookielib.CookieJar()headler=urllib2.HTTPCookieProcessor(cj)opener=urllib2.build_opener(headler)url="http://jwgl.ntu.edu.cn/cjcx/Default.aspx"#登录页面url1="http://jwgl.ntu.edu.cn/cjcx/checkImage.aspx"#验证码页面scoreurl="http://jwgl.ntu.edu.cn/cjcx/Data/ScoreAllData.aspx"#获取分数cjidurl="http://jwgl.ntu.edu.cn/cjcx/Data/EvaluationCourseData.aspx"tijiaourl="http://jwgl.ntu.edu.cn/cjcx/actions/SubmitEvaluationTeaching.aspx"def  login():#输入数据print u"××××××××××××××××××××南通大学教务系统登陆××××××××××××××××××××"print u"输入学号!"xh=raw_input()print u"输入身份证号!"sfzh=raw_input()print u"密码!"kl=raw_input()yzm=opener.open(url1)yzmgif=open("yzm.gif","w")yzmgif.write(yzm.read())yzmgif.close()print u"验证码已保存在本文件目录下(yzm.gif),请查看并输入!"yzmstr=raw_input()#数据保存jilu=open(xh+".txt","w")jilu.write("学号:"+xh+"\n身份证号:"+sfzh+"\n密码:"+kl)jilu.close()values={"__VIEWSTATE":"/wEPDwUJODExMDE5NzY5ZGRgtUdRucUbXsT8g55XmVsTwV6PMw==","__VIEWSTATEGENERATOR":"6C0FF253","xh":xh,"sfzh":sfzh,"kl":kl,"yzm":yzmstr}scoreValues={"start":"0","pageSize":"80"}#loginrequest=urllib2.Request(url,urllib.urlencode(values))f=opener.open(request)def pingjiao():#get cjid  cjidRequest=urllib2.Request(cjidurl)cjid=opener.open(cjidRequest)cjidstr=cjid.read()print cjidstrrestr='"cjid":"(.*?)"(.*?)"kcmc":"(.*?)"'restr1='true'pattern=re.compile(restr)pattern1=re.compile(restr1)items=re.findall(pattern,cjidstr)for item in items:#print item[0],item[2]print 'subject:'+item[2]+'  is doing... 'pjcsValues={"cjid":item[0],"cpjg":"111111111","advice":""}resultR=urllib2.Request(tijiaourl,urllib.urlencode(pjcsValues))result=opener.open(resultR)resultstr=result.read()#print resultstrrestr=re.findall(pattern1,resultstr)#print resultstrif restr!=[] and restr[0]=='true':print 'success'else:print 'failed'login()pingjiao()



0 0