代码主体
python代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| import requests import json def send_message(token, title, content): url = "http://www.pushplus.plus/send" data = {"token": token, "title": title, "content": content} body = json.dumps(data).encode(encoding="utf-8") headers = {"Content-Type": "application/json"} print(requests.post(url, data=body, headers=headers))
token = 'token值填入这里'
try: f = open('old.txt', 'r') except: f = open('old.txt', 'w') f.write('0') f.close() old = int(f.read()) f.close()
print(old)
url = 'https://www.gupt.edu.cn/jwglxt/cjcx/cjcx_cxDgXscj.html?doType=query&gnmkdm=N305005'
cookies={'route':'route值填入这里','JSESSIONID':'JSESSIONID值填入这里'}
response = requests.post(url=url,cookies=cookies) try: new = len(response.json()['items']) except: send_message(token,'运行异常','无法获取到成绩信息,可能是cookies过期了!') new = 0
if new > old: contentlist = sorted(response.json()['items'], key=lambda x: x['cjbdsj'])
content = '' for i in range(1,new - old+1): kcmc = contentlist[-i]['kcmc'].replace(' ','') cj = contentlist[-i]['cj'] join = '更新了:' + kcmc + '的成绩' + ' 成绩为:' + cj + '\n' content = content + join
send_message(token, '成绩更新啦!',content)
f = open('old.txt', 'w') f.write(str(new)) f.close()
|
使用教程
获取pushplus token
在下方链接根据提示使用微信注册,并关注其微信公众号,获取 pushplus 的 token
一对一消息|pushplus(推送加)-微信消息推送平台
将获取到的token值放入到代码的 第12行 中



获取教务系统cookies
因为我们学校使用账号密码登录要还是要二次验证码,所以直接手动填cookies
在电脑浏览器(以edge浏览器为例)上登录教务系统,登录后打开下方链接:
https://www.gupt.edu.cn/jwglxt/cjcx/cjcx_cxDgXscj.html?doType=query&gnmkdm=N305005
打开后按 F12 ,选择 网络 ,勾选 保留日志

然后刷新该页面,点击如图出现的数据,选择标头

往下滑,找到 请求标头

在 请求标头 处 找到 Cookies

Cookies 最后两行 有 route 和 JSESSIONID

将其对应填入第30行中

这两个参数配置对了,才能获取到你的成绩
效果图
