超星上课自动签到[python]
本帖最后由 初心超级酷 于 2021-12-8 14:31 编辑最近学习python突发奇想写了个python的超星自动签到
目前只支持手势签到、普通签到和位置签到 还有一些bug还望大佬指出
源代码只做学习使用,不可用于商业盈利或非法用途
源代码只做学习使用,不可用于商业盈利或非法用途
源代码只做学习使用,不可用于商业盈利或非法用途
import time
import requests
import base64
from requests.exceptions import ReadTimeout
from lxml import etree
import json
import sys
import random
import json
# 字符串提取
def extract(str):
return (str.split(';')).split('=')
# 登录
def login():
# 首次访问登录页所得的响应头,以及页面内容
LOGIN_PAGE = 'http://passport2.chaoxing.com/mlogin?fid=&newversion=true&refer=http%3A%2F%2Fi.chaoxing.com'
# 请求参数
params = {
'fid': '-1', 'pid': '-1', 'refer': 'http%3A%2F%2Fi.chaoxing.com', '_blank': '1', 't': 'true',
'vc3': 'NULL', '_uid': 'null', '_d': 'null', 'uf': 'null'
}
response = requests.get(LOGIN_PAGE, params)
paramsData = {
'data':'uname=这里是手机号&password=这里是base64加密后的密码&fid=-1&t=true&refer=http://i.chaoxing.com'
}
# phone = '这里是手机号'
# pwd = 'pwd'
phone = input('请输入手机号:')
pwd = input('请输入base64加密后的密码:')
#设置请求链接
LOGIN = 'http://passport2.chaoxing.com/fanyalogin?uname='+ phone +'&password='+ pwd +'&fid=-1&t=true&refer=http://i.chaoxing.com'
# 设置请求头
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
# 登录
response = requests.post(LOGIN, headers=headers, params=paramsData)
obj = json.loads(response.text)
# 登陆失败
if obj['status'] != True:
print(obj['msg2'])
sys.exit()
# 拿到请求后的响应头获取set-cookie字段
setCookie = (response.headers['set-cookie']).split(',')
# fid = (setCookie.split(';')).split('=')
fid = extract(setCookie)
uid = extract(setCookie)
uf = extract(setCookie)
d = extract(setCookie)
vc3 = extract(setCookie)
params =
return params
# 获取用户名
def getUser(params):
# 请求链接
ACCOUNTMANAGE = 'http://passport2.chaoxing.com/mooc/accountManage'
# 请求头
# 设置请求头
headers = {
'Cookie': 'uf={uf}; _d={d}; UID={uid}; vc3={vc3};'.format(uf=params,d=params,uid=params,vc3=params)
}
response = requests.get(ACCOUNTMANAGE, headers=headers)
return xPATH(response.text, "//*[@id=\"messageName\"]/text()")
# 获取标签内的名称
def xPATH(content, regular):
# 解析HTML文档,返回根节点对象
html = etree.HTML(content)
# 获取节点
result = html.xpath(regular)
return result
# 获取所有课程
def getCourses(params):
# 获取请求链接
COURSELIST = 'http://mooc1-1.chaoxing.com/visit/courselistdata?courseType=1&courseFolderId=0&courseFolderSize=0'
# 解决304重定向问题
user_agent_list = [
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/61.0",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15",
]
# 设置请求头
headers = {
'Accept': 'text/html, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': random.choice(user_agent_list),
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;',
'Cookie': '_uid={uid}; _d={d}; vc3={vc3}'.format(uid=params, d=params, vc3=params)
}
# print(headers)
data = {
'courseType': '1',
'courseFolderId': '0',
'courseFolderSize': '0'
}
print('获取列表中请等待...')
time.sleep(3)
response = requests.post(COURSELIST, headers=headers, params=data)
CoursesList = []
# 获取课程courseId 和 classId
AllCourses = xPATH(response.text, "//*[@class=\"course clearfix\"]/@id")
for i in AllCourses:
arr = i.split('_')
CoursesList.append({'courseId':arr,'classId':arr})
return CoursesList
def getSignActivity(courses,params):
print('正在查询可签到的课程中')
for i in courses:
ACTIVELIST = "https://mobilelearn.chaoxing.com/v2/apis/active/student/activelist?fid=0&courseId={courseId}&classId={classId}&_={Data}".format(courseId=i.get('courseId'),classId=i.get('classId'),Data=int(round((time.time())*1000)))
headers = {
'Cookie': 'uf={uf}; _d={d}; UID={uid}; vc3={vc3};'.format(uf=params,d=params,uid=params,vc3=params)
}
response = requests.get(ACTIVELIST, headers=headers)
o = json.loads(response.text)
# 查看课程中是否存在内容
if len(o['data']['activeList']) != 0:
activeList = o['data']['activeList']
# 判断课程中是否存在otherId
if 'otherId' in activeList:
otherId = int(activeList['otherId'])
status = int(activeList['status'])
# 判断课程是否在有效期
if (otherId >= 0 and otherId <= 4) and status == 1:
# 活动开始超过一小时则忽略
if ((int(round((time.time())*1000)) - int(activeList['startTime'])) / 1000) < 3600:
print('检测到活动:'+activeList['nameOne'])
return activeList
# 手势、普通签到
def GeneralSign(Sign,params,Name):
PPTSIGN = "https://mobilelearn.chaoxing.com/pptSign/stuSignajax?activeId={activeId}&uid={uid}&clientip=&latitude=-1&longitude=-1&appType=15&fid={fid}&name={name}".format(activeId=Sign['id'],uid=params,fid=params,name=Name)
headers = {
'Cookie': 'uf={uf}; _d={d}; UID={uid}; vc3={vc3};'.format(uf=params,d=params,uid=params,vc3=params)
}
response = requests.get(PPTSIGN, headers=headers)
print(response.text)
# 位置签到
def LocationSign(params,Name,Sign):
print('参考网站:https://api.map.baidu.com/lbsapi/getpoint/index.html')
lnglat = input('经纬度,如\"113.516288,34.817038\": ')
# 纬度
lat = lnglat.split(',')
# 经度
lon = lnglat.split(',')
address = input('详细地址: ')
PPTSIGN = "https://mobilelearn.chaoxing.com/pptSign/stuSignajax?name={name}&address={address}&activeId={activeId}&uid={uid}&clientip=&latitude={lat}&longitude={lon}&fid={fid}&appType=15&ifTiJiao=1".format(name=Name,address=address,activeId=Sign['id'],uid=params,lat=lat,lon=lon,fid=params)
headers = {
'Cookie': 'uf={uf}; _d={d}; UID={uid}; vc3={vc3};'.format(uf=params, d=params, uid=params,vc3=params)
}
response = requests.get(PPTSIGN, headers=headers)
print(response.text)
# 签到模式
# pattern = input('请选择签到模式1.二维码签到;2.位置签到;3.普通、手势签到;4.拍照签到\n')
# 获取cookie
parmsData = login()
# 获取用户名
userName = getUser(parmsData)
print('欢迎:'+userName)
# 获取所有课程
courses = getCourses(parmsData)
# 获取签到中的课程
SignActivity = getSignActivity(courses, parmsData)
print('签到的课程参数',SignActivity)
if SignActivity:
# 手势签到
if SignActivity['nameOne'] == '签到' or SignActivity['nameOne'] == '手势签到':
GeneralSign(SignActivity,parmsData,userName)
elif SignActivity['nameOne'] == '位置签到':
LocationSign(parmsData,userName,SignActivity)
else:
print('未检测到活动')
# 问题1 不知道哪门课程签到成功 同学私信我留个联系方式交流呀 拿走了但是
import time
import requests
import base64
from requests.exceptions import ReadTimeout
from lxml import etree
import json
这三个颜色区域为什莫会报错啊 studenter 发表于 2021-12-5 14:46
拿走了但是
import time
import requests
报错的都去安装一下模块 你手机号密码都泄露了 nianboy 发表于 2021-12-6 12:26
你手机号密码都泄露了
忘记修改了{:1_896:} 不错不错 我学习一下 学习了!思路值得好好学习一下{:1_921:}
页:
[1]