def updateLog(self, courseOpenId, openClassId, moduleId, cellId, cellLogId, picNum, studyNewlyTime, studyNewlyPicNum, token): uri = "https://zjy2.icve.com.cn/api/common/Directory/stuProcessCellLog" headers = { 'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8", 'Accept-Encoding': "gzip, deflate, br", 'Origin': "https://zjy2.icve.com.cn", 'X-Requested-With': "XMLHttpRequest", 'Referer': "https://zjy2.icve.com.cn/common/directory/directory.html?courseOpenId=%s&openClassId=%s&cellId=%s&flag=s&moduleId=%s" % (courseOpenId, openClassId, cellId, moduleId) } data = obj2str({ 'courseOpenId': courseOpenId, 'openClassId': openClassId, 'cellId': cellId, 'cellLogId': cellLogId, 'picNum': picNum, 'studyNewlyTime': studyNewlyTime, 'studyNewlyPicNum': studyNewlyPicNum, 'token': token }) r = self.s.post(uri, headers=headers, data=data) ret = json.loads(r.text) return ret['code'] == 1
def commentVideo(self, courseOpenId, openClassId, cellId, moduleId, content, star): uri = "https://zjy2.icve.com.cn/api/common/Directory/addCellActivity" headers = { 'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8", 'Accept-Encoding': "gzip, deflate, br", 'Origin': "https://zjy2.icve.com.cn", 'X-Requested-With': "XMLHttpRequest", 'Referer': "https://zjy2.icve.com.cn/common/directory/directory.html?courseOpenId=%s&openClassId=%s&cellId=%s&flag=s&moduleId=%s" % (courseOpenId, openClassId, cellId, moduleId) } data = obj2str({ 'courseOpenId': courseOpenId, 'openClassId': openClassId, 'cellId': cellId, 'content': content, 'docJson': "", 'star': star, 'activityType': 1 }).encode(encoding="utf-8") r = self.s.post(uri, headers=headers, data=data) ret = json.loads(r.text) return ret['code'] == 1
def choiceCourse(self, courseOpenId, openClassId, cellId, moduleId, cellName): uri = "https://zjy2.icve.com.cn/api/common/Directory/changeStuStudyProcessCellData" headers = { 'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8", 'Accept-Encoding': "gzip, deflate, br", 'Origin': "https://zjy2.icve.com.cn", 'X-Requested-With': "XMLHttpRequest", 'Referer': "https://zjy2.icve.com.cn/common/directory/directory.html?courseOpenId=%s&openClassId=%s&cellId=%s&flag=s&moduleId=%s" % (courseOpenId, openClassId, cellId, moduleId) } data = obj2str({ 'courseOpenId': courseOpenId, 'openClassId': openClassId, 'cellId': cellId, 'moduleId': moduleId, 'cellName': cellName }).encode(encoding="utf-8") r = self.s.post(uri, headers=headers, data=data) ret = json.loads(r.text) return ret['code'] == 1
def login_m(self, u_name, u_pass): uri = "https://app.51xuexiaoyi.com/api/v1/login" headers = { 'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8", 'Accept-Encoding': "gzip, deflate, br" } data = obj2str({ 'username': u_name, 'password': u_pass }) r = self.s.post(uri, headers=headers, data=data) res = json.loads(r.text) if res['code'] == 200: token = res['data']['api_token'] self.s.headers.update({ 'token': token }) return res['code'] == 200
def get_task_finish_status(self, clazzid, cpi, nodes, courseid): headers = { 'Content-Type': "application/x-www-form-urlencoded", 'Accept-Encoding': 'gzip, deflate, br', 'Origin': "http://i.mooc.chaoxing.com/", 'Referer': "http://passport2.chaoxing.com/login?fid=&refer=http://i.mooc.chaoxing.com" } node = ','.join([str(i) for i in nodes]) data = obj2str({ 'clazzid': clazzid, 'userid': self.uid, 'view': 'json', 'cpi': cpi, 'nodes': node, 'courseid': courseid }) r = self.s.post("https://mooc1-api.chaoxing.com/job/myjobsnodesmap", headers=headers, data=data) if r.text != "": return json.loads(r.text) return None
def login(self, u_name, u_pass, code): headers = { 'Content-Type': "application/x-www-form-urlencoded", 'Accept-Encoding': 'gzip, deflate, br', 'Origin': "http://i.mooc.chaoxing.com/", 'Referer': "http://passport2.chaoxing.com/login?fid=&refer=http://i.mooc.chaoxing.com" } uri = "http://passport2.chaoxing.com/login?refer=" + \ quote("http://i.mooc.chaoxing.com", "utf-8") data = obj2str({ 'refer_0x001': quote("http://i.mooc.chaoxing.com", "utf-8"), 'pid': "-1", 'pidName': "", 'fid': "-1", 'fidName': "", 'allowJoin': "0", 'isCheckNumCode': "1", 'f': "0", 'productid': "", 't': "true", 'uname': u_name, 'password': base64.b64encode(u_pass.encode("utf-8")).decode('ascii'), 'numcode': code, 'verCode': "" }) r = self.s.post(uri, headers=headers, data=data, allow_redirects=False) if r.status_code != 302: rule = r'id=\"show_error\">(.*?)</td>' d = re.findall(rule, r.text) print(d[0]) return False else: return True
def get_course_page(self, courseId, clazzid, chapterId, cpi): uri = "https://mooc1-1.chaoxing.com/mycourse/studentstudyAjax" data = obj2str({ 'courseId': courseId, 'clazzid': clazzid, 'chapterId': chapterId, 'cpi': cpi, 'verificationcode': "" }) headers = { 'Content-Type': "application/x-www-form-urlencoded", 'Accept-Encoding': 'gzip, deflate, br', 'Origin': "http://i.mooc.chaoxing.com/", } r = self.s.post(uri, headers=headers, data=data) rc = re.findall(r'<span (.*?)</span>', r.text, re.DOTALL) ret = [] # 判断是否只有一页 if len(rc) == 0: title = re.findall(r'<h1>(.*?)</h1>', r.text, re.DOTALL) url = re.findall(r'/knowledge/cards\?(.*?)\"', r.text, re.DOTALL) ret.insert( len(ret), { 'title': title[0], 'url': "https://mooc1-1.chaoxing.com/knowledge/cards?%s" % url[0] }) else: for item in rc: title = re.findall(r'title=\"(.*?)\"', item) paras = re.findall(r'\d{1,}', item) num = int(paras[0]) - 1 totalnum = paras[1] chapterId = paras[2] courseId = paras[3] clazzid = paras[4] ret.insert( len(ret), { 'title': title[0], 'url': "https://mooc1-1.chaoxing.com/knowledge/cards?clazzid=%s&courseid=%s&knowledgeid=%s&num=%d&ut=s&cpi=%s&v=20160407-1" % (clazzid, courseId, chapterId, num, cpi) }) return ret
def getCourseCata(self, courseOpenId, openClassId): uri = "https://zjy2.icve.com.cn/api/study/process/getProcessList" headers = { 'Content-Type': "application/x-www-form-urlencoded", 'Accept-Encoding': 'gzip, deflate, br', } # 获取一级目录 r = self.s.post(uri, headers=headers, data=obj2str({ 'courseOpenId': courseOpenId, 'openClassId': openClassId })) ret = json.loads(r.text) if ret['code'] != 1: raise Exception("获取目录时,出现异常!") length = len(ret['progress']['moduleList']) i = 0 # 遍历 获取二级目录 while i < length: item = ret['progress']['moduleList'][i] # 先进行判断 # 看看是否是 100% 避免去获取已经完成的视频的二级目录 if item['percent'] == 100: i = i + 1 continue # 获取二级模块id moduleId = item['id'] ret2 = self.getLevelCata(courseOpenId, moduleId) ret['progress']['moduleList'][i]['data'] = ret2['topicList'] i = i + 1 return ret['progress']['moduleList']
def getTaskInfo(self, courseOpenId, openClassId, cellId, moduleId): uri = "https://zjy2.icve.com.cn/api/common/Directory/viewDirectory" headers = { 'Content-Type': "application/x-www-form-urlencoded", 'Accept-Encoding': 'gzip, deflate, br', } data = obj2str({ 'courseOpenId': courseOpenId, 'openClassId': openClassId, 'cellId': cellId, 'flag': "s", 'moduleId': moduleId }) r = self.s.post(uri, headers=headers, data=data) return json.loads(r.text)
def login(self, u_name, u_pass, code): uri = "https://zjy2.icve.com.cn/api/common/login/login" headers = { 'Content-Type': "application/x-www-form-urlencoded", 'Accept-Encoding': 'gzip, deflate, br', 'Origin': "https://zjy2.icve.com.cn", 'Referer': "https://zjy2.icve.com.cn/portal/login.html" } data = obj2str({ 'userName': u_name, 'userPwd': u_pass, 'verifyCode': code }) r = self.s.post(uri, headers=headers, data=data) ret = json.loads(r.text) return ret['code'] == 1
def searchCourse(self, key): uri = "https://app.51xuexiaoyi.com/api/v1/course/searchCourse" headers = { 'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8", 'Accept-Encoding': "gzip, deflate, br" } data = obj2str({ 'keyword': key }).encode(encoding="utf-8") r = self.s.post(uri, headers=headers, data=data) res = json.loads(r.text) if res['code'] != 200: return [] return res['data']
def getData(self, courseOpenId, openClassId, topicId): uri = "https://zjy2.icve.com.cn/api/study/process/getCellByTopicId" headers = { 'Content-Type': "application/x-www-form-urlencoded", 'Accept-Encoding': 'gzip, deflate, br', } data = obj2str({ 'courseOpenId': courseOpenId, 'openClassId': openClassId, 'topicId': topicId }) r = self.s.post(uri, headers=headers, data=data) ret = json.loads(r.text) if ret['code'] != 1: raise Exception("获取任务时,出现异常!") return ret['cellList']
def getLevelCata(self, courseOpenId, moduleId): uri = "https://zjy2.icve.com.cn/api/study/process/getTopicByModuleId" headers = { 'Content-Type': "application/x-www-form-urlencoded", 'Accept-Encoding': 'gzip, deflate, br', } # 获取二级目录 r = self.s.post(uri, headers=headers, data=obj2str({ 'courseOpenId': courseOpenId, 'moduleId': moduleId })) ret = json.loads(r.text) if ret['code'] != 1: raise Exception("获取目录时,出现异常!") return ret
def login_m(self, u_name, u_pass): uri = "https://zjyapp.icve.com.cn/newMobileAPI/MobileLogin/newLogin" headers = { 'Content-Type': "application/x-www-form-urlencoded", 'Accept-Encoding': 'gzip, deflate, br', } data = obj2str({ 'appVersion': "2.8.21", 'clientId': "057386f8991f402498dfc38ed5cb7e49", 'equipmentApiVersion': "14.1", 'equipmentAppVersion': "2.8.21", 'equipmentModel': "iPhone%2012", 'sourceType': "3", 'userName': u_name, 'userPwd': u_pass }) r = self.s.post(uri, headers=headers, data=data) ret = json.loads(r.text) return ret['code'] == 1
def getComment(self, courseOpenId, openClassId, moduleId, cellId): uri = "https://zjy2.icve.com.cn/api/common/Directory/getCellCommentData" headers = { 'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8", 'Accept-Encoding': "gzip, deflate, br", 'Origin': "https://zjy2.icve.com.cn", 'X-Requested-With': "XMLHttpRequest", 'Referer': "https://zjy2.icve.com.cn/common/directory/directory.html?courseOpenId=%s&openClassId=%s&cellId=%s&flag=s&moduleId=%s" % (courseOpenId, openClassId, cellId, moduleId) } data = obj2str({ 'courseOpenId': courseOpenId, 'openClassId': openClassId, 'cellId': cellId, 'type': "0", }) r = self.s.post(uri, headers=headers, data=data) ret = json.loads(r.text) if ret['code'] != 1: return [] size = ret['pagination']['totalCount'] if size <= 8: return ret['list'] uri = "https://zjy2.icve.com.cn/common/Directory/getCellCommentData" listData = ret['list'] index = 1 while index * 8 < size: index = index + 1 data = obj2str({ 'courseOpenId': courseOpenId, 'openClassId': openClassId, 'cellId': cellId, 'type': "0", 'pageSize': 8, 'page': index }) r = self.s.post(uri, headers=headers, data=data) ret = json.loads(r.text) for z in ret['list']: listData.insert(len(listData), z) return listData