前言
实在是不想早起啊
其实刚开网课的那几天就已经写好了,用了一段时间了,现在发出来。具体如何实现的,请自己看一下代码内容(学习通是真的垃圾,登录都是 GET 的)
脚本
如果需要持久运行的话,需要自己补一下异常捕获。垃圾学习通日常 HTTP 超时
#!/usr/bin/env python3
import logging, requests, time, re
USERNAME = ''
PASSWORD = ''
logging.basicConfig(format="[%(asctime)s][%(levelname)s] %(message)s", datefmt="%d-%M-%Y %H:%M:%S", level=logging.INFO)
client = requests.Session()
client.headers.update({
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 Edg/80.0.361.50'
})
count = 0
while True:
if not count:
logging.info('正在登录中')
r = client.get('http://i.chaoxing.com/vlogin?userName={}&passWord={}'.format(USERNAME, PASSWORD), timeout = 10)
if r.json()["success"]:
logging.info('登录成功')
else:
logging.warning('登录失败')
logging.warning(r.text)
time.sleep(10)
continue
count += 1
client.get('http://i.chaoxing.com/base', timeout = 10)
time.sleep(0.25)
client.get('http://i.chaoxing.com/base/userOrg', timeout = 10)
time.sleep(0.25)
r = client.get('http://passport2.chaoxing.com/mooc.jsp', timeout = 10)
time.sleep(0.2)
mco = re.compile('name="courseId" value="([0-9]+)"')
courses = mco.findall(r.text)
logging.info('已获取 {} 个课程:{}'.format(len(courses), courses))
mcc = re.compile('name="classId" value="([0-9]+)"')
classes = mcc.findall(r.text)
logging.info('已获取 {} 个班级:{}'.format(len(classes), classes))
for i in range(0, len(courses)):
ma = re.compile('activeDetail\(([0-9]+),[0-9]+,[A-Z0-9a-z]+\)')
r = client.get('https://mobilelearn.chaoxing.com/widget/pcpick/stu/index?courseId={}&jclassId={}'.format(courses[i], classes[i]), timeout = 10)
time.sleep(0.5)
actives = ma.findall(r.text)
logging.info('在 {} {} 中获取到 {} 个活动:{}'.format(courses[i], classes[i], len(actives), actives))
if not len(actives):
continue
n = 0
for x in actives:
n += 1
r = client.get('https://mobilelearn.chaoxing.com/widget/sign/pcStuSignController/signIn?activeId={}&classId={}&courseId={}'.format(x, classes[i], courses[i]), timeout = 10)
if '签到成功' in r.text:
logging.info('已向 {} 发送签到请求:成功'.format(x))
else:
logging.info('已向 {} 发送签到请求:失败'.format(x))
if n == 3:
break
time.sleep(1)
if count == 10:
count = 0
logging.info('在 30 秒后重新读取数据')
time.sleep(30)