本帖最后由 bone 于 2022-11-11 23:58 编辑
基于@nianboy的预约作品,发现座位每天早上要签到,不然会导致违约。故在大佬代码的基础上删减增加实现签到。
[Python] 纯文本查看 复制代码 # -*- coding: utf8 -*-
# coder:nianboy
# modify:bone
# time:2022-11-11
import requests
import re
import datetime
class ChaoXing:
def __init__(self, seatId):
today = datetime.datetime.now()
self.today= today
self.seatId = seatId
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 sceen_data(self, id, start_time, end_time, name, pwd):
global today_time
start_time = start_time + "%3A00"
end_time = end_time + "%3A30"
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)
page_url = ("http://office.chaoxing.com/data/apps/seat/reserve/info?id=" + str(
id) + "&seatNum=" + str(
self.seatId) )
page_resp = self. session.get(url=page_url, headers=self.headers).text
self.pageToken = re.findall(r"馆)\",\"id\":(\d+)", page_resp)[0]
url = (
"http://office.chaoxing.com/data/apps/seat/sign?id=" + str(
self.pageToken)
)
print(self.today)
page_text = self.session.get(url=url, headers=self.headers).text
if '"success":true' in page_text:
print(url + "房间号:" + str(
id) + " 座位号:" + str(
self.seatId) + " 签到成功!")
else:
print(url + page_text + "房间号:" + str(
id) + " 座位号:" + str(
self.seatId) + " 签到失败!")
if __name__ == "__main__":
chaoxing = ChaoXing(seatId="09") # 座位号
chaoxing.sceen_data(id="26", start_time="10", end_time="21", name='', pwd='')
# id需要抓包,start_time是预约开始时间,end_time是结束预约时间,name是学习通账号,pwd是学习通密码 |