本帖最后由 nianboy 于 2022-10-19 14:47 编辑
上一版接口新增参数,然后小小改动了一下代码,目前可以自动获取上次一预约的图书馆id,省去抓包步骤,截至目前为止还是可以成功预约的!
[Python] 纯文本查看 复制代码
import requestsimport reimport jsonimport timeimport datetimeclass 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)[0] 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[i]["week"] == week: dict = {} dict["startTime"] = page_dicts[i]["startTime"] dict["endTime"] = page_dicts[i]["endTime"] dict["id"] = page_dicts[i]["id"] dict["week"] = page_dicts[i]["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'][0]['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[i]["startTime"] end_time = self.nowtime + " " + today_time[i]["endTime"] id = today_time[i]["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 = https://www.52pojie.cn/json.dumps(reserveUsers, ensure_ascii=False)'{"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()