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

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3596|回复: 14
收起左侧

[Python 转载] 基于Python和selenium的广东省专业技术人员远程教育学习脚本

[复制链接]
lntuer 发表于 2019-10-18 11:53
本帖最后由 lntuer 于 2019-10-18 11:54 编辑

一、介绍
广东省专业技术人员远程教育网址:http://ggfw.gdhrss.gov.cn/ssologin/login?service=http://ggfw.gdhrss.gov.cn/gdggfw/index.shtml
二、功能
①基于Python和selenium半自动化登陆、pyautogui模块;
1.png
②自动学习该课程目录下所有课程和学习;
2.png
③可以后台观看视频并静音播放
3.png
代码如下:
[Python] 纯文本查看 复制代码
from selenium import webdriver
import pyautogui
import time
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import re
import random
username="你的账号:"
passwd="你的密码:"
login_url='http://ggfw.gdhrss.gov.cn/ssologin/login?service=http://ggfw.gdhrss.gov.cn/gdggfw/index.shtml'
option = webdriver.ChromeOptions()
option.add_argument('--mute-audio')
browser = webdriver.Chrome(chrome_options=option)
browser.maximize_window()
browser.get(login_url)
browser.implicitly_wait(10)
elem=browser.find_element_by_id("username_personal")
elem.clear()
elem.send_keys(username)
time.sleep(1)
elem=browser.find_element_by_id("password_personal")
elem.clear()
elem.send_keys(passwd)
time.sleep(1)
code_num=pyautogui.prompt("请输入验证码:")
elem=browser.find_element_by_id("vcode_personal")
elem.clear()
elem.send_keys(code_num)
elem=browser.find_element_by_id('doPersonLogin')
elem.click()
time.sleep(3)
browser.get('需要学习的课程目录地址:')
time.sleep(3)
js_001='document.getElementsByClassName("append-plugin-tip")[0].click();'
js_005='return document.getElementsByClassName("append-plugin-tip").length;'
browser.execute_script(js_001)
time.sleep(3)
video_unstudy_num=browser.execute_script(js_005)
time.sleep(3)
for i in range(0,int(video_unstudy_num)):
    js_006='document.getElementsByClassName("append-plugin-tip")[{}].click();'.format(i)
    browser.execute_script(js_006)
    time.sleep(1)
    js_002 = 'p.play()'
    browser.execute_script(js_002)
    time.sleep(1)
    js_003 = 'return document.getElementById("realPlayVideoTime").textContent;'
    js_004 = 'return document.getElementById("askTime").textContent;'
    video_real_time = browser.execute_script(js_003)
    time.sleep(1)
    video_total_time = browser.execute_script(js_004)
    print(video_real_time,video_total_time)
    remain_time = int((int(str(video_total_time)[:2]) * 3600 + int(str(video_total_time)[3:5]) * 60 + int(str(video_total_time)[-2:]))*((101-int(video_real_time))/100))
    print("该课程还有{}秒未学习……".format(remain_time))
    first_time=time.time()
    print(first_time)
    def find_question(count_time):
        try:
            WebDriverWait(browser,count_time,0.5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="aadiv"]/div')))
            browser.find_element_by_xpath('//*[@id="aadiv"]/div').click()
            time.sleep(1)
            browser.find_element_by_xpath('//*[@id="from_ejectque"]/div[2]/a').click()
            time.sleep(1)
            browser.find_element_by_xpath("/html/body/div[5]/div[3]/a/span/span").click()
            print("答题完毕……")
        except:
            print("未发现需要答题的题目……")
    find_question(remain_time)
    second_time=time.time()
    print(second_time)
    first_remain_time=int(second_time - first_time)
    print("第一次答题共等待了{}秒".format(first_remain_time))
    third_time=time.time()
    print(third_time)
    time.sleep(3)
    find_question(remain_time-first_remain_time+10)
    time.sleep(3)
    four_time=time.time()
    print(four_time)
    second_remain_time=int(four_time-third_time)
    print("第二次答题共等待了{}秒".format(second_remain_time))
    for unstart_time in range(0,remain_time-first_remain_time+10-second_remain_time):
        print("该课程还有{}秒未学习……".format(remain_time-first_remain_time+10-second_remain_time-unstart_time))
        time.sleep(1)
    time.sleep(3)

有的老铁反映Python和selenium安装比较麻烦(但是自动化程度高啊),下面还有JavaScript代码,写的比较水,可以用但是不能全部自动化,具体用法为F12,打开开发者工具输入代码回车:
[JavaScript] 纯文本查看 复制代码
        setInterval(function(){
                        document.getElementsByClassName("exam-subject-text-queanswar-answer")[0].click();
                        document.getElementsByClassName("reply-sub")[0].click();
                        document.getElementsByClassName("l-btn-text")[0].click();
                },1000)

声明:仅限个人学习使用,严禁商业使用,否则后果自负,如有违规,管理直接删帖!
最后,原创不易,还希望大家可以高抬贵手免费评个分!!!
2.png

免费评分

参与人数 4吾爱币 +5 热心值 +4 收起 理由
ourcctv + 1 我很赞同!
Superbai + 1 + 1 我很赞同!
v.n.lee + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
苏紫方璇 + 3 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

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

 楼主| lntuer 发表于 2019-10-19 16:41
v.n.lee 发表于 2019-10-19 16:06
大佬厉害,有js操作的教程吗想学习学习

我也是网上找的,JavaScript基础很差,之前自学Python
 楼主| lntuer 发表于 2019-10-19 16:41

很中肯,但是我现在在学习JavaScript,想二者结合一下!
a4445001 发表于 2019-10-18 12:03
vethenc 发表于 2019-10-18 12:05
感谢分享,怎么扩展到其他省的平台呢
额微粒波地 发表于 2019-10-18 12:26
感谢分享
q6378561 发表于 2019-10-18 13:43
表面python 本质js
MarkChan 发表于 2019-10-18 14:32
感谢分享,这是非常实用的东西!
yicx01 发表于 2019-10-18 15:24
基于Python下的JS吗?
v.n.lee 发表于 2019-10-19 16:06
大佬厉害,有js操作的教程吗想学习学习
您需要登录后才可以回帖 登录 | 注册[Register]

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

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

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

GMT+8, 2024-4-26 23:16

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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