diff --git a/__pycache__/get_info.cpython-310.pyc b/__pycache__/get_info.cpython-310.pyc index 4993b54..4c586a4 100644 Binary files a/__pycache__/get_info.cpython-310.pyc and b/__pycache__/get_info.cpython-310.pyc differ diff --git a/__pycache__/kill_course.cpython-310.pyc b/__pycache__/kill_course.cpython-310.pyc index 487713a..d479e03 100644 Binary files a/__pycache__/kill_course.cpython-310.pyc and b/__pycache__/kill_course.cpython-310.pyc differ diff --git a/__pycache__/single_course.cpython-310.pyc b/__pycache__/single_course.cpython-310.pyc index d41db22..a3b6f98 100644 Binary files a/__pycache__/single_course.cpython-310.pyc and b/__pycache__/single_course.cpython-310.pyc differ diff --git a/course_info.json b/course_info.json index 6331538..fa5bdb7 100644 --- a/course_info.json +++ b/course_info.json @@ -1,157 +1 @@ -{ - "7367": { - "rate": 100, - "type": "\u5fc5\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7366": { - "rate": 100, - "type": "\u5fc5\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7033": { - "rate": 100, - "type": "\u5fc5\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7517": { - "rate": 100, - "type": "\u5fc5\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7032": { - "rate": 100, - "type": "\u5fc5\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7516": { - "rate": 100, - "type": "\u5fc5\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7031": { - "rate": 100, - "type": "\u5fc5\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7515": { - "rate": 100, - "type": "\u5fc5\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "6349": { - "rate": 100, - "type": "\u5fc5\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7436": { - "rate": 100, - "type": "\u5fc5\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "6937": { - "rate": 100, - "type": "\u57f9\u8bad", - "status": "\u672a\u8bc4\u5206" - }, - "6938": { - "rate": 100, - "type": "\u57f9\u8bad", - "status": "\u672a\u8bc4\u5206" - }, - "6991": { - "rate": 15, - "type": "\u57f9\u8bad", - "status": "\u672a\u5b66\u5b8c" - }, - "6992": { - "rate": 100, - "type": "\u57f9\u8bad", - "status": "\u5df2\u5b66\u5b8c" - }, - "6993": { - "rate": 100, - "type": "\u57f9\u8bad", - "status": "\u5df2\u5b66\u5b8c" - }, - "6995": { - "rate": 100, - "type": "\u57f9\u8bad", - "status": "\u5df2\u5b66\u5b8c" - }, - "7006": { - "rate": 100, - "type": "\u57f9\u8bad", - "status": "\u5df2\u5b66\u5b8c" - }, - "7007": { - "rate": 100, - "type": "\u57f9\u8bad", - "status": "\u5df2\u5b66\u5b8c" - }, - "7010": { - "rate": 100, - "type": "\u57f9\u8bad", - "status": "\u5df2\u5b66\u5b8c" - }, - "7011": { - "rate": 100, - "type": "\u57f9\u8bad", - "status": "\u5df2\u5b66\u5b8c" - }, - "7554": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7553": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7552": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7551": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7550": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7549": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7548": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7547": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7546": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7545": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - }, - "7564": { - "rate": 100, - "type": "\u9009\u4fee", - "status": "\u5df2\u5b66\u5b8c" - } -} \ No newline at end of file +{"6349": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7436": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7367": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7366": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7033": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7517": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7032": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7516": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7031": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7515": {"rate": 100, "type": "\u5fc5\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "6937": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "6938": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u672a\u8bc4\u5206"}, "6991": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u672a\u8bc4\u5206"}, "6992": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "6993": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "6995": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7006": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7007": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7010": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7011": {"rate": 100, "type": "\u57f9\u8bad", "status": "\u5df2\u5b66\u5b8c"}, "7554": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7553": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7552": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7551": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7550": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7549": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7548": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7547": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7546": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7545": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}, "7564": {"rate": 100, "type": "\u9009\u4fee", "status": "\u5df2\u5b66\u5b8c"}} \ No newline at end of file diff --git a/demo.py b/demo.py index 4e3b81f..2b61483 100644 --- a/demo.py +++ b/demo.py @@ -1,4 +1,10 @@ -from DrissionPage import ChromiumPage -from DrissionPage.common import * -page = ChromiumPage() -page.ele('tag:a@@text():是').click() \ No newline at end of file +from collections import * +import json +info = json.load(open('course_info.json', 'r')) +cnt = defaultdict(list) +new_cnt = defaultdict(list) +for k, v in info.items(): + new_cnt[v['type']].append((k,v['rate'],v['status'])) # 课程类型作为键,课程id作为值 +print(new_cnt) +for k,v in new_cnt.items(): + print(k,v) \ No newline at end of file diff --git a/get_info.py b/get_info.py index 9ef8ae8..b0f73b1 100644 --- a/get_info.py +++ b/get_info.py @@ -4,35 +4,63 @@ from collections import * import time import json from loguru import logger +import subprocess # http://hnqmgc.17el.cn/grzx/ -def get_info(): - # 创建页面对象,并启动或接管浏览器 +# 单独实现登录操作 +def login(first:bool=True): + if not first: + return + # 先检查当前页面是否已经登录 page = WebPage() - # 跳转到登录页面 try: - page.get('http://hnqmgc.17el.cn/grzx/',retry=5,timeout=5,interval=1) + if page.ele('tag:div@@text():欢迎您,',timeout=3): + logger.info('当前页面已登录') + return except BaseException: - logger.error('网络连接失败') + logger.info('准备登录') + if first: + try: + page.get('http://hnqmgc.17el.cn/grzx/',retry=5,timeout=5,interval=1) + except BaseException: + logger.error('网络连接失败') - # 定位到账号文本框,获取文本框元素 - ele = page.ele('#userName') # #的意思是通过id定位元素 - # 输入对文本框输入账号 - ele.input('51140220050507901X') - # 定位到密码文本框并输入密码 - page.ele('#password').input('hnqm123456') - # 定位到验证码文本框并输入验证码 - inpcode = page.ele('#yzcode').text # 湖南青马太可爱了吧,验证码居然直接放在页面源码里:) - page.ele('#inpcode').input(inpcode) - # 点击登录按钮 - page.ele('#btnLogin').click() - # 进入课程页面 - page.ele('.wxtsBox-button').click() # 关闭提示页面 - page.ele('#login_btn').click() - page.ele('@value=进入个人中心').click() + # 定位到账号文本框,获取文本框元素 + ele = page.ele('#userName') # #的意思是通过id定位元素 + # 输入对文本框输入账号 + ele.input('51140220050507901X') + # 定位到密码文本框并输入密码 + page.ele('#password').input('hnqm123456') + # 定位到验证码文本框并输入验证码 + inpcode = page.ele('#yzcode').text # 湖南青马太可爱了吧,验证码居然直接放在页面源码里:) + page.ele('#inpcode').input(inpcode) + # 点击登录按钮 + page.ele('#btnLogin').click() + page.wait.new_tab(3) + # 进入课程页面 + try: + if page.ele('@onclick=cha()',timeout=3): + page.ele('@onclick=cha()').click() + # + elif page.ele('tag:img@@style=width: 25px;height: 25px;',timeout=3): + page.ele('tag:img@@style=width: 25px;height: 25px;').click() + except BaseException: + logger.error('不能进入课程页面') + subprocess.run(["python", __file__]) + exit() + page.ele('#login_btn').click() + page.ele('@value=进入个人中心').click() +def get_info(first:bool=True): + # 创建页面对象,并启动或接管浏览器 + page = WebPage() + # 登录 + login(first) # 提取课程信息 time.sleep(2) - page.ele('@value=0').click() + if not first: + page.refresh() + time.sleep(2) + page.ele('@value=0',timeout=3).click() # 获取总页数 course_info = {} #