【已失效】超星学习通图书馆预约(更新免抓包版)
本帖最后由 nianboy 于 2023-3-26 14:49 编辑上一版接口新增参数,然后小小改动了一下代码,目前可以自动获取上次一预约的图书馆id,省去抓包步骤,截至目前为止还是可以成功预约的!
import requests
import re
import json
import time
import datetime
class ChaoXing(object):
def __init__(self,phase):
self.phase = phase
today = datetime.datetime.now()
self.nowtime = today.strftime("%Y-%m-%d")
self.lasttime = (today + datetime.timedelta(days=1)).strftime("%Y-%m-%d")
self.headers = {
"User-agent": "Mozilla/4.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36",
}
self.session = requests.session()
def session_token(self, name, pwd):
login_api = "https://passport2.chaoxing.com/api/login"
params = {
"name": name,# 学习通账号
"pwd": pwd,# 学习通密码
"verify": "0",
"schoolid": "",
}
self.session.get(login_api, params=params, headers=self.headers)
def sceen_data(self):
global today_time
url = (
"http://office.chaoxing.com/front/web/apps/reservepc/item?fidEnc=bb3acc50f157286e&reserveId=2656&itemId="
+ self.itemId
)
r1 = self.session.post(url=url, headers=self.headers).text
self.token = re.findall(r"_this, {}, '(.*?)'", r1)
url = (
"http://office.chaoxing.com/data/apps/reserve/item/setting?reserveId=2656&itemId="
+ self.itemId
)
page_text = self.session.get(url=url, headers=self.headers).text
page_dict = json.loads(page_text)
page_dicts = page_dict["data"]["reserveIntervalList"]
today_time = []
for i in range(len(page_dicts)):
week = datetime.datetime.now().weekday() + 1
if page_dicts["week"] == week:
dict = {}
dict["startTime"] = page_dicts["startTime"]
dict["endTime"] = page_dicts["endTime"]
dict["id"] = page_dicts["id"]
dict["week"] = page_dicts["week"]
today_time.append(dict)
def get_itemId(self):
#此方法会获取上一次预约图书馆的id,省去抓包步骤
url = "http://office.chaoxing.com/data/apps/reservepc/user/histroy?page=1&reserveId=2656&sw="
item_text = self.session.get(url, headers=self.headers).text
item_text = json.loads(item_text)
itemId = str(item_text['data']['rows']['itemId'])
self.itemId = itemId
def get_sign(self):
global id, start_time, end_time
for i in range(0, self.phase):
start_time = self.nowtime + " " + today_time["startTime"]
end_time = self.nowtime + " " + today_time["endTime"]
id = today_time["id"]
year_month = time.strftime("%Y") + "_" + str(int(time.strftime("%W")) - 1)
year_week = time.strftime("%Y") + "_" + str(int(time.strftime("%W")) + 1)
reserveUsers = [
{"itemId": self.itemId,
"starttime": start_time,
"endtime": end_time,
"today": self.nowtime,
"yearWeek": year_week,
"yearMonth": year_month,
"intervalIds": "[{}]".format(id),
"remark": "",
"formsData": "null",
"formUserId": "null",
"aprvId": "null",
"aprvStatusTypeId": "null"}
]
fromData = json.dumps(reserveUsers, ensure_ascii=False)
data = {
"itemId": self.itemId,
"reserveId": "2656",
"reserveUsers": fromData,
"token": self.token,
"formsData": "",
"formUserId": "",
"aprvId": "",
"aprvStatusTypeId": "",
"reserveNum": "1",
"cycleType": "0"
}
r2 = self.session.post(
"http://office.chaoxing.com/data/apps/reserve/submit/reserve",
headers=self.headers,
data=data,
).text
if r2 == '{"data":{"reserveUsers":[],"errData":[]},"success":true}':
print("预约成功!")
else:
print(r2)
if __name__ == "__main__":
chaoxing = ChaoXing(phase=3)#默认预约第三个时段
chaoxing.session_token(name="", pwd="")#学习通账号密码
chaoxing.get_itemId()
chaoxing.sceen_data()
chaoxing.get_sign()
Traceback (most recent call last):
File "E:\PytharmProject\XueXiTongLibrary.py", line 114, in <module>
chaoxing.get_itemId()
File "E:\PytharmProject\XueXiTongLibrary.py", line 61, in get_itemId
itemId = str(item_text['data']['rows']['itemId'])
~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
超雪牛逼 谢谢大侠分享,还是没有搞明白。 有什么用?没有明白 tianyagd 发表于 2022-10-19 18:51
有什么用?没有明白
超星的图书馆预约功能,用过的人应该知道 dhwl9899 发表于 2022-10-19 18:44
谢谢大侠分享,还是没有搞明白。
哪里没明白 eeyy11 发表于 2022-10-21 07:41
请问如果我要使用此代码,需要改动哪些地方才能预约成功
如果你有预约记录的话,直接在113行填进自己的学习通账号密码就好 在哪里运行啊? 小白一个:rggrg 小王子123 发表于 2022-10-23 14:40
在哪里运行啊? 小白一个
python的编译器就可以 你不能用的话 可能和楼主的超星版本不一样