commit 8eb8db61373a13a9801b40124176a594d821a12f Author: JesterHey Date: Sat Mar 9 12:31:56 2024 +0800 new file: demo.py new file: main.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/cyan_horse.iml b/.idea/cyan_horse.iml new file mode 100644 index 0000000..8437fe6 --- /dev/null +++ b/.idea/cyan_horse.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..e4077de --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,24 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..dc9ea49 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7c13155 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/demo.py b/demo.py new file mode 100644 index 0000000..38a3822 --- /dev/null +++ b/demo.py @@ -0,0 +1,6 @@ +from DrissionPage import ChromiumPage + +# 创建页面对象,并启动或接管浏览器 +page = ChromiumPage() +# 跳转到登录页面 +page.get('https://g1879.gitee.io/drissionpagedocs/get_start/examples/control_browser') \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..fadf71e --- /dev/null +++ b/main.py @@ -0,0 +1,54 @@ +from DrissionPage import WebPage +from DrissionPage.common import * +import time +import json +# http://hnqmgc.17el.cn/grzx/ + + +# 创建页面对象,并启动或接管浏览器 +page = WebPage() +# 跳转到登录页面 +page.get('http://hnqmgc.17el.cn/grzx/') + +# 定位到账号文本框,获取文本框元素 +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() +# 提取课程信息 +time.sleep(2) +page.ele('@value=0').click() +# 获取总页数 +course_info = {} +#
1 / 4
+total_page = int(page.ele('.paginationjs-nav J-paginationjs-nav').text[-1]) +for i in range(total_page): + # 逐页读取课程信息和完成状态并存放到字典中 + tbodys = page.ele('#tbody') + # 获取tbody下的所有tr + trs = tbodys.eles('tag:tr') + for tr in trs: + cur_info = tr.text.split('\t') + print(cur_info) + course_id = cur_info[0] # 课程id + course_rate = cur_info[3] # 课程完成百分比 + course_status = cur_info[4] # 课程完成状态(是否完成习题/评价) + # 存放到字典中 + course_info[course_id] = {'rate': course_rate, 'status': course_status} + if i != total_page - 1: + page.ele('@type=text').input(i + 2) + page.ele('@value=跳转').click() + time.sleep(1) +print(len(course_info)) +page.close_session() +