吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3089|回复: 7
收起左侧

[Python 转载] 超星上课自动签到[python]

  [复制链接]
初心超级酷 发表于 2021-12-1 09:52
本帖最后由 初心超级酷 于 2021-12-8 14:31 编辑

最近学习python突发奇想写了个python的超星自动签到
目前只支持手势签到、普通签到和位置签到 还有一些bug还望大佬指出
源代码只做学习使用,不可用于商业盈利或非法用途
源代码只做学习使用,不可用于商业盈利或非法用途
源代码只做学习使用,不可用于商业盈利或非法用途
[Python] 纯文本查看 复制代码

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(';')[0]).split('=')[1]

# 登录
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[3].split(';')[0]).split('=')[1]
    fid = extract(setCookie[3])
    uid = extract(setCookie[5])
    uf = extract(setCookie[7])
    d = extract(setCookie[9])
    vc3 = extract(setCookie[17])

    params = [fid,uid,uf,d,vc3]
    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[2],d=params[3],uid=params[1],vc3=params[4])
    }
    response = requests.get(ACCOUNTMANAGE, headers=headers)
    return xPATH(response.text, "//*[@id=\"messageName\"]/text()")[0]

# 获取标签内的名称
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[1], d=params[3], vc3=params[4])
    }
    # 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[1],'classId':arr[2]})

    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[2],d=params[3],uid=params[1],vc3=params[4])
        }
        response = requests.get(ACTIVELIST, headers=headers)
        o = json.loads(response.text)
        # 查看课程中是否存在内容
        if len(o['data']['activeList']) != 0:
            activeList = o['data']['activeList'][0]
            # 判断课程中是否存在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[1],fid=params[0],name=Name)
    headers = {
                 'Cookie': 'uf={uf}; _d={d}; UID={uid}; vc3={vc3};'.format(uf=params[2],d=params[3],uid=params[1],vc3=params[4])
            }
    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(',')[1]
    # 经度
    lon = lnglat.split(',')[0]
    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[1],lat=lat,lon=lon,fid=params[0])
    headers = {
        'Cookie': 'uf={uf}; _d={d}; UID={uid}; vc3={vc3};'.format(uf=params[2], d=params[3], uid=params[1],vc3=params[4])
    }
    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 不知道哪门课程签到成功

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

i462618232 发表于 2021-12-2 16:20
同学私信我留个联系方式交流呀
studenter 发表于 2021-12-5 14:46
拿走了但是
import time
import requests
import base64
from requests.exceptions import ReadTimeout
from lxml import etree
import json
这三个颜色区域为什莫会报错啊
北极熊ice 发表于 2021-12-6 10:38
nianboy 发表于 2021-12-6 12:26
你手机号密码都泄露了
 楼主| 初心超级酷 发表于 2021-12-7 18:29
nianboy 发表于 2021-12-6 12:26
你手机号密码都泄露了

忘记修改了
zgbest8 发表于 2021-12-7 22:12
不错不错 我学习一下
chuohaogulang 发表于 2021-12-19 20:24
学习了!思路值得好好学习一下
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-1-13 07:24

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表