选课系统有四个板块,每个版块的请求地址均不相同,他们处于不同的数据库中。
“本学期计划选课”,“专业内跨年级选课”,“跨专业选课”,“公选课”
应当在每一门课程属性中增加一个属性(p[2])
修改后代码如下:
import random
import requests
import re
import time
import json
s = requests.Session()
r = s.get('https://cas.sustech.edu.cn/cas/login?service=http%3A%2F%2Fjwxt.sustech.edu.cn%2Fjsxsd%2F')
print(str(r.content, 'utf-8'))
#记得写账号和密码
data = {
'username': '',
# 'username': '',
'password': '',
# 'password': 'abcdefg',
'execution': re.findall('on" value="(.+?)"', r.text)[0],
'_eventId': 'submit',
'geolocation': ''
}
#进入教务系统
r = s.post('https://cas.sustech.edu.cn/cas/login?service=http%3A%2F%2Fjwxt.sustech.edu.cn%2Fjsxsd%2F', data)
print(str(r.content, 'utf-8'))
print("CAS验证成功")
#查看选课是否开始
r = s.get('http://jwxt.sustech.edu.cn/jsxsd/xsxk/xklc_list?Ves632DSdyV=NEW_XSD_PYGL')
print("教务系统启动")
count = 1
while True:
count += 1
key = re.findall('href="(.+)" target="blank">进入选课', r.text)
# print(r.text)
print(str(key))
if len(key) == 1:
break
print('喵喵祈祷中……开始第 %d 次祈祷' % count)
time.sleep(random.random()*random.random())
k = key[0]
print('榴莲启动完成')
print("开始抢课")
s.get('http://jwxt.sustech.edu.cn' + k)
list = [["概率論與數理統計",'201920201001721','bxqjh']]
bxqjh-本學期計劃選課,zynknj-專業內跨年級選課,kzy-跨專業選課,gxk-公選課選課
每一門課有三個信息:["課程名稱",'課程編號','課程類別']
def add_class(oneclass):
list.append(oneclass)
def rush_all(list):
count2 = 1
while True:
print('开始第 %d 次喵喵喵' % count2)
for p in list:
count2 += 1
if rush(p):
list.remove(p)
def rush(p):
print('正在抢 %s' % p[0])
if p[2]=='bxqjh':
r = s.get("http://jwxt.sustech.edu.cn/jsxsd/xsxkkc/bxqjhxkOper?jx0404id=%s&xkzy=&trjf=" % p[1])
elif p[2]=='zynknj':
r = s.get("http://jwxt.sustech.edu.cn/jsxsd/xsxkkc/knjxkOper?jx0404id=%s&xkzy=&trjf=" % p[1])
elif p[2]=='kzy':
r = s.get("http://jwxt.sustech.edu.cn/jsxsd/xsxkkc/fawxkOper?jx0404id=%s&xkzy=&trjf=" % p[1])
else:
r = s.get("http://jwxt.sustech.edu.cn/jsxsd/xsxkkc/ggxxkxkOper?jx0404id=%s&xkzy=&trjf=" % p[1])
result = str(r.content, 'utf-8')
# print(result.find("true", 0, len(result)))
if result.find("true", 0, len(result)) >= 1:
print("抢到 "+ p[0] + " 啦")
return True
# print(str(json.loads(result)['success']) + "····\n正在继续加油!\n")
delay = random.random()*random.random()
print(result + "\n正在继续加油!\n············%f s 后" % delay)
time.sleep(delay)
return False
print("空气动力学")
print(str(r.content, 'utf-8'))
print("\n退课")
print(str(r.content, 'utf-8'))
rush_all(list)
s.close()