湖州师范学院图书馆官网(湖州职业技术学院图书
家电维修 2023-07-16 19:16www.caominkang.com家电维修技术
期末抢座位很麻烦,模拟点击脚本抢的又太慢,毕业了用不到了,留给后来人
写了个request脚本
理论上旧版IC空间管理系统都可以用
原文链接:https://.hyluz./?id=57131
python脚本#coding:utf-8 import time import requests import json import re import datetime as da import pymysql import sys #reload(sys) //py2 #sys.setdefaultencoding('utf-8') //py2 from datetime import datetime # 增加相对路径,这样可以进行相对引用 sys.path.append("..") # 建立数据库连接 conn = pymysql.connect( host='127.0.0.1', port=3306, user='tsg', passd='XXXX', #数据库密码 db="tsg", charset='utf8mb4') #数据库部分,用于查找座位的id下面给出该表的数据,需自行搭建,或写死 cursor = conn.cursor() # 执行完毕返回的结果默认以元组的形式保存 def selectData(condition): cursor.execute("SELECT kindId,devId,labId FROM stainfo WHERe seatName='{seatName}'".format(seatName=condition)) # 使用 execute() 方法执行 SQL 查询,注意有引号 data = cursor.fetchone() # print(data) # 关闭sql连接 print(data) #cursor.close() #conn.close() return data def run(user,passd,seatName,starttime,endtime,days): dayss="" for i in days: dayss=dayss+str((int(i)+7-2)%7) dayss=dayss.replace('0','7') print(dayss) day=str(datetime.no().isoeekday()) if(day not in dayss): print(user+"未设置预约") return 1 loginUrl = "http://icspace.lib.zjhu.edu./ClientWeb/pro/ajax/login.aspx" headers = { 'User-Agent': 'Mozilla/5.0 (Windos NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' } def logout(): res = r.get(url="http://icspace.lib.zjhu.edu./ClientWeb/pro/ajax/login.aspx?act=logout",headers=headers,timeout=5) print(res.text) def getScheduled(kindid, devid, labid, data, starttime, endtime): scheduledUrl = "http://icspace.lib.zjhu.edu./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=0 i=0 res = r.get(url=scheduledUrl.format(kindid, devid, labid, data, starttime, data, endtime),headers=headers,timeout=5) print(i,datetime.no(),res.text) if "操作成功" in res.text: flag=1 elif "方可预约" in res.text: flag=0 #time.sleep(0.005) else: flag=1 logout() return flag r = requests.session() loginData = { "act": "login", "id": user, "pd": passd } key = "SCT39442TVtfq4drt4J3Zb81NAeocdAJ8" # 登录获取cookie r.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() afterTomorro = today + da.timedelta(days=2) # print(afterTomorro) resp=getScheduled(kindid, devid,labid,afterTomorro,starttime,endtime) if(resp==0): return 1 #time.sleep(0.1) #run(user,passd,seatName,starttime,endtime,days) #return 0 my_datas = "" url_myReverse = "http://icspace.lib.zjhu.edu./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)) for index,data in enumerate(datas): if index == 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) + "nn" print("my_datas:",my_datas) except Exception as e: print(1) return 0 time.sleep(3) flag=1 hile(flag): try: print(datetime.no()) flag=run('20180821xx','xxxxxx','西7F135','8:00','21:30',"1234567") #学号,密码,座位号,开始时间,结束时间,周几预约 1代表星期六预约周一的,7代表星期五预约周日的 except: flag=1 cursor.close() conn.close()运行截图
上一篇:301转向有哪些用途?
下一篇:c#实现隐藏与显示任务栏的办法详解