期末抢座位很麻烦,模拟点击脚本抢的又太慢,毕业了用不到了,留给后来人
写了个request脚本
理论上旧版IC空间管理系统都可以用
原文链接:/?id=57131
python脚本:
#coding:utf-8importtimeimportrequestsimportjsonimportreimportdatetimeasdaimportpymysqlimportsys#reload(sys)//py2#sys.setdefaultencoding('utf-8')//py2fromdatetimeimportdatetime#增加相对路径,这样可以进行相对引用sys.path.append("..")#建立数据库连接conn=pymysql.connect(host='127.0.0.1',port=3306,user='tsg',passwd='XXXX',#数据库密码db="tsg",charset='utf8mb4')#数据库部分,用于查找座位的id下面给出该表的数据,需自行搭建,或写死cursor=conn.cursor()#执行完毕返回的结果默认以元组的形式保存defselectData(condition):cursor.execute("SELECTkindId,devId,labIdFROMstainfoWHEREseatName='{seatName}'".format(seatName=condition))#使用execute()方法执行SQL查询,注意有引号data=cursor.fetchone()#print(data)#关闭sql连接print(data)#cursor.close()#conn.close()returndatadefrun(user,passwd,seatName,starttime,endtime,days):dayss=""foriindays:dayss=dayss+str((int(i)+7-2)%7)dayss=dayss.replace('0','7')print(dayss)day=str(datetime.now().isoweekday())if(daynotindayss):print(user+"未设置预约")return1loginUrl="http://icspace.lib./ClientWeb/pro/ajax/login.aspx"headers={'User-Agent':'Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/76.0.3809.100Safari/537.36'}deflogout():res=r.get(url="http://icspace.lib./ClientWeb/pro/ajax/login.aspx?act=logout",headers=headers,timeout=5)print(res.text)defgetScheduled(kindid,devid,labid,data,starttime,endtime):scheduledUrl="http://icspace.lib./ClientWeb/pro/ajax/reserve.aspx?kind_id={}&dev_id={}&lab_id={}&type=dev&prop=&test_id=&resv_id=&term=&min_user=&max_user=&mb_list=&start={}%20{}&end={}%20{}&memo=&act=set_resv"flag=0i=0res=r.get(url=scheduledUrl.format(kindid,devid,labid,data,starttime,data,endtime),headers=headers,timeout=5)print(i,datetime.now(),res.text)if"操作成功"inres.text:flag=1elif"方可预约"inres.text:flag=0#time.sleep(0.005)else:flag=1logout()returnflagr=requests.session()loginData={"act":"login","id":user,"pwd":passwd}key="SCT39442TVtfq4drt4J3Zb81NAeocdAJ8"#登录获取cookier.post(loginUrl,data=loginData,headers=headers,timeout=5)#根据位置号从数据库查出信息infos=selectData(seatName)kindid=infos[0]devid=infos[1]labid=infos[2]print(r.cookies)today=da.date.today()afterTomorrow=today+da.timedelta(days=2)#print(afterTomorrow)resp=getScheduled(kindid,devid,labid,afterTomorrow,starttime,endtime)if(resp==0):return1#time.sleep(0.1)#run(user,passwd,seatName,starttime,endtime,days)#return0my_datas=""url_myReverse="http://icspace.lib./ClientWeb/pro/ajax/reserve.aspx?stat_flag=9&act=get_my_resv"try:myReverse=r.get(url=url_myReverse,headers=headers,timeout=5)datas=json.loads(myReverse.text)['data']#print("datas:",datas)#print(len(datas))forindex,datainenumerate(datas):ifindex==len(datas)-1:tmp_tuple=(data["timeDesc"],data["devName"],)my_datas+=str(tmp_tuple)else:tmp_tuple=(data["timeDesc"],data["devName"],)my_datas+=str(tmp_tuple)+"\n\n"print("my_datas:",my_datas)exceptExceptionase:print(1)return0time.sleep(3)flag=1while(flag):try:print(datetime.now())flag=run('0821xx','xxxxxx','西7F135','8:00','21:30',"1234567")#学号,密码,座位号,开始时间,结束时间,周几预约1代表星期六预约周一的,7代表星期五预约周日的except:flag=1cursor.close()conn.close()
运行截图:
如果觉得《湖州师范学院 湖州学院 图书馆抢座位脚本》对你有帮助,请点赞、收藏,并留下你的观点哦!