作者电脑水平极差, 硬做了个安全教育平台的全自动做题机. 输入账号密码便可自动做安全教育平台题目
使用说明:
语言: python3 需要在代码源文件所在目录下建立”ids.txt”文件, 其内写有账号与密码. 格式如下:
代码
import re,requests,time
url=rhttps://jiangsulogin.xueanquan.com/LoginHandler.ashx
headers = {User-Agent:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0}
def do_survey(course,soj_session):
print(开始做,course)
u=course[–1][2:–2]
#有时候它给的网址以index结尾, 实际上是个重定向, 这样手动重定向一下
url21=
url22=
if index not in u:
url21=u
else:
v=u[0:u.find(“index”)]
url21=v+shipin.html
url22=v+video.html
print(survey,url21, url22)
speId=0
try:
res1=soj_session.get(url21,headers=headers)
res1.encoding=utf-8
html1=res1.text
speId=re.findall(rdata-specialId ??=”(.*?)”,html1)[0]
except Exception as e:
try:
res2=soj_session.get(url22,headers=headers)
res2.encoding=utf-8
html2=res2.text
speId=re.findall(rdata-specialId ??=”(.*?)”,html2)[0]
except Exception as e1:
print(html1)
print(html2)
print(匹配失败)
return –1
url3=https://huodongapi.xueanquan.com/p/jiangsu/Topic/topic/platformapi/api/v1/records/sign
soj_session.post(url3,json={specialId:speId,“step”:1},headers=headers)
soj_session.post(url3,json={specialId:speId,“step”:2},headers=headers)
def do_li(course,soj_session):
print(开始做,course)
li=course[0]
gid=course[3]
url2=https://suzhou.xueanquan.com/JiaTing/EscapeSkill/SeeVideo.aspx?gid=789&li={}.format(li)
res_test=soj_session.get(url2,headers=headers)
print(url2)
html=res_test.text
#步骤一
videoid=re.search(rVideoID == “(.*)”,html).group(1)
data3=videoid={}gradeid={}courseid={}.format(videoid,gid,li)
url4=https://suzhou.xueanquan.com/jiating/ajax/FamilyEduCenter.EscapeSkill.SeeVideo,FamilyEduCenter.ashx?_method=SkillCheckName&_session=rw
res=soj_session.post(url4,data=data3,headers=headers)
#步骤二
#准备好答案包
string=re.search(rSeeVideo.TemplateIn2\((.*)\),html).group(1)
strings=string.split(,)
data2=workid={}fid={}title=
require=
purpose=
contents=
testwanser=
testinfo=
testMark=100
testReulst=1
SiteName=
siteAddrees=
watchTime=
CourseID={}.format(strings[0][1:–1],strings[1][2:–1],strings[–1][2:–1])
# 发答案
url3=https://suzhou.xueanquan.com/jiating/ajax/FamilyEduCenter.EscapeSkill.SeeVideo,FamilyEduCenter.ashx?_method=TemplateIn2&_session=rw
res=soj_session.post(url3,data=data2,headers=headers)
res.encoding=utf-8
if res.text==“-1”:
print(失败做,course)
return –1
else:
# print(成功做,course,status_code=,res.text)
pass
def do_winsum(course,soj_session):
print(先pass,course)
pass
def get_ids():
返回 二维矩阵[[账号,密码,姓名],…]
id=[]
text=
with open(ids.txt,r) as f:
while True:
t=f.readline()
if t==:
break
elif t==\n:
continue
else:
se=re.search(r(.*) (.*) (.*),t)
id.append([se.group(1),se.group(2),se.group(3)])
# print(id)
return id
def do(id):
输入id
做对应id的题目
#先登录
data={
userName:id[0],
password:id[1],
type:login,
}
soj_session = requests.session()
res=soj_session.post(url,data=data,headers=headers)#登录
res.encoding=utf-8
html=res.text
if rret:-1 in html:
print(id,无法登录)
return –1
else:
print(id,登录成功)
#获得班级作业列表(包括自己已经做过的)
grade=re.findall(r“Grade:(.*?)”,html)[0]
classroom=re.findall(r“ClassRoom:(.*?)”,html)[0]
cityid=re.findall(r“CityCode:(.*?)”,html)[0]
url1=https://file.safetree.com.cn/webapi.jiangsu/jt/MyHomeWork.html?grade={}&classroom={}&cityid={}.format(grade,classroom,cityid)
res1=requests.get(url1)
res1.encoding=utf-8
html1=res1.text
courses=re.findall(“showhdtcbox\((.*?)\)”,html1)
courses=courses[1:]
courses2=[]
for c in courses:
c=c.replace(,)
c=c.split(,)
if c not in courses2:
courses2.append(c)
print(id,作业清单获取成功)
#做作业
result=0
for i in range(len(courses2)):
# time.sleep(1)
if int(courses2[i][0]) == –1:
if do_survey(courses2[i],soj_session)==-1:
result += –1
elif int(courses2[i][0]) > 0:
if do_li(courses2[i],soj_session)==-1:
result += –1
elif int(courses2[i][0]) == 0:
if do_winsum(courses2[i],soj_session)==-1:
result += –1
print(做完,id[2],异常数:, 0–result)
if __name__ == “__main__”:
ids=get_ids()
for id in ids:
do(id)
还存在的问题:
尚未解决寒暑假特殊作业的自动化, 不过那种作业一年也就两次, 平时这个小东西也够用了
更新日志:
2020/12/5: 平台对部分网址添加了后缀导致识别错误.
免责声明:文章内容来自互联网,本站仅提供信息存储空间服务,真实性请自行鉴别,本站不承担任何责任,如有侵权等情况,请与本站联系删除。
转载请注明出处:全自动安全教育平台(安全自动装置包括哪些) https://www.bxbdf.com/a/45181.shtml