吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1185|回复: 1
收起左侧

[求助] 求助大佬帮忙解决一下网课脚本问题

[复制链接]
大大大菠萝 发表于 2021-11-19 11:28
25吾爱币
import requests
import time
import json
################### Config #############################
cookie_xsid = '5039058A7FAB95A'
########################################################
class AutoCompleteOnlineCourse:
    def __init__(self) -> None:
        # headers
        session = requests.Session()
        session.headers['Cookie'] = 'player=1; xsid=' + cookie_xsid
        session.headers['Connection'] = 'close'
        session.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) ' \
                                        'AppleWebKit/537.36 (KHTML, like Gecko) ' \
                                        'Chrome/80.0.3987.122 Safari/537.36'
        session.headers['Host'] = 'www.cqooc.net'
        self.Session = session
    def main(self) -> None:
        info = self.getInfomation()
        try:
            print(info.json()['msg'])
            print("xsid有误,请检查!")
            return
        except:
            pass
        self.ownerId = info['id']
        self.username = info['username']
        print("Login ID:", self.username)
        courseData = []
        for index, i in enumerate(self.getCourseInfo()['data']):
            print("{}{}".format(index + 1, i['title']))
            courseData.append({
                "title": i['title'],
                "parentId": i['id'],
                "courseId": i['courseId']
            })
        while True:
            try:
                id = input('请选择课程(序号):')
                self.title = courseData[int(id) - 1]['title']
                break
            except:
                print("输入有误,请重新输入!")
                continue
        self.parentId = courseData[int(id) - 1]['parentId']
        self.courseId = courseData[int(id) - 1]['courseId']
        print("\n已选择 {}\n".format(self.title))
        self.startLearnCourse()
    def getInfomation(self) -> json:
        """
        获取基本信息
        :return:
        """
        return self.Session.get('http://www.cqooc.net/user/session?xsid=' + cookie_xsid).json()
    def getCourseInfo(self) -> json:
        """
        获取课程信息
        :return:
        """
        self.Session.headers['Referer'] = 'http://www.cqooc.net/my/learn'
        return self.Session.get(
            'http://www.cqooc.net/json/mcs?sortby=id&reverse=true&del=2&courseType=2&ownerId={}&limit=10'.format(
                self.ownerId)).json()
    def getCompleteCourse(self) -> list:
        """
        获取已完成小节列表
        :return:
        """
        self.Session.headers['Referer'] = 'http://www.cqooc.net/learn/mooc/progress?id=' + self.courseId
        data = self.Session.get(
            'http://www.cqooc.net/json/learnLogs?limit=100&start=1&sortby=id&courseId={}&select=sectionId&username={}'.format(
                self.courseId, self.username))
        CourseIdList = []
        for i in data.json()['data']:
            CourseIdList.append(i['sectionId'])
        return CourseIdList
    def startLearn(self) -> json:
        self.Session.headers['Referer'] = 'http://www.cqooc.net/learn/mooc/structure?id=' + self.courseId
        return self.Session.post(url='http://www.cqooc.net/account/session/api/login/time', json={
            "username": self.username
        }).json()
    def getLog(self, sectionId) -> json:
        self.Session.headers['Referer'] = 'http://www.cqooc.net/learn/mooc/structure?id=' + self.courseId
        return self.Session.get(
            'http://www.cqooc.net/json/learnLogs?sectionId=' + sectionId + '&username=' + self.username).json()
    def checkProgress(self, courseId, sectionId, chapterId) -> None:
        count = 0
        while True:
            self.Session.headers['Referer'] = 'http://www.cqooc.net/learn/mooc/structure?id=' + courseId
            self.startLearn()
            self.getLog(sectionId)
            time.sleep(2)
            self.startLearn()
            time.sleep(1)
            Log = self.Session.post('http://www.cqooc.net/learnLog/api/add', json={
                "action": 0,
                "category": 2,
                "chapterId": str(chapterId),
                "courseId": str(courseId),
                "ownerId": self.ownerId,
                "parentId": str(self.parentId),
                "sectionId": int(sectionId),
                "username": self.username
            })
            if count <= 2:
                date = 40
            else:
                date = 150
            if Log.json()['msg'] == '已经添加记录' or Log.json()['msg'] == 'No error':
                return
            else:
                time.sleep(date)
                count += 1
                continue
    def startLearnCourse(self) -> None:
        sectionList = \
            self.Session.get('http://www.cqooc.net/json/chapter/lessons?courseId=' + self.courseId).json()['data'][0]['body']
        index_t = 0
        CompleteCourse = self.getCompleteCourse()
        print("已完成小节数: {} ".format(len(CompleteCourse)))
        for chapterId, sectionIds in sectionList.items():
            print(
                '章节剩余: %d/%d(%.2f%%)' % (
                    index_t + 1, len(sectionList.items()), ((float((index_t + 1) / len(sectionList.items()))) * 100)))
            index_t += 1
            for index, sectionId in enumerate(sectionIds):
                print('    小节剩余: %d/%d(%.2f%%)' % (
                    index + 1, len(sectionIds), (float((index + 1) / len(sectionIds)) * 100)), end='')
                if sectionId in CompleteCourse:
                    print(' 已完成,跳过!')
                    continue
                print(' 成功!')
                self.checkProgress(self.courseId, sectionId, chapterId)
if __name__ == '__main__':
    AutoCompleteOnlineCourse().main()
发生异常: JSONDecodeError

Expecting value: line 1 column 1 (char 0)  File "[url=]C:\Users\[/url]菠萝大大\Desktop\账号密码\01.py", line 127, in checkProgress    if Log.json()['msg'] == '已经添加记录' or Log.json()['msg'] == 'No error':  File "[url=]C:\Users\[/url]菠萝大大\Desktop\账号密码\01.py", line 153, in startLearnCourse    self.checkProgress(self.courseId, sectionId, chapterId)  File "[url=]C:\Users\[/url]菠萝大大\Desktop\账号密码\01.py", line 55, in main    self.startLearnCourse()  File "[url=]C:\Users\[/url]菠萝大大\Desktop\账号密码\01.py", line 157, in <module>    AutoCompleteOnlineCourse().main()







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

Prozacs 发表于 2021-11-19 15:33
Log = self.Session.post( 请求做判断,如果结果不是json格式,而是错误页面503, if Log.json()['msg'] == '已经添加记录' or Log.json()['msg'] == 'No error':,那么你这里怎么转json取值呢。

if Log.status_code == 200:
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

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

GMT+8, 2024-5-13 06:46

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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