1.环境配置工作
①安装python3环境
安装完关闭窗口!!!
②查看自己的Chrome浏览器版本下载对应的无头浏览器
无头浏览器放在我的资源里了,也可以去这里下载
http://chromedriver.storage.googleapis.com/index.html
网站偶尔会不能开
最后给无头浏览器添加环境变量
之后一直点击确定!!!!!!!(不然不生效)
2.编写脚本
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver import ChromeOptions
import time
def go(page,username_text,pwd_text):
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
# 全程隐藏浏览器
option.add_argument("headless")
# 全程静音播放
option.add_argument("--mute-audio")
driver = webdriver.Chrome(r'chromedriver.exe',options=option)
driver.get('http://hw.neusoft.edu.cn/hw/lrn/lrn.do?cno=74005CC401&teachingclassno=200456-002')
driver.maximize_window()
#登录
#具体内容请在资源里下载
# 切换下一个页面
looka = 1
move=0
# 观看视频
driver.quit()
def gotext(page,chapter,username_text,pwd_text):
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
# 全程隐藏浏览器
option.add_argument("headless")
# 全程静音播放
option.add_argument("--mute-audio")
driver = webdriver.Chrome(r'chromedriver.exe', options=option)
driver.get('http://hw.neusoft.edu.cn/hw/lrn/lrn.do?cno=74005CC401&teachingclassno=200456-002')
driver.maximize_window()
# 进行登录
#具体内容请在资源里下载
# 按钮初始化下标
looka=1
move=0
# 开始看课程
#具体内容请在资源里下载
driver.quit()
if __name__ == '__main__':
index=0
allcount = 1
print('输入你的登录账户==默认学号')
username=input()
print('输入你的登录密码==默认身份证号后六位')
pwd=input()
# 下标从1开始 最终到30结束
print('输入从第几章开始')
actionpage=input()
print('输入从第几小节开始')
chapter=input()
for i in range(int(actionpage),31):
if index==0:
print('开始第'+str(i)+'章')
gotext(i,chapter,username,pwd)
print('第' + str(i) + '章结束')
index+=1
allcount+=1
else:
print('开始第' + str(i) + '章')
gotext(i,1,username,pwd)
print('第' + str(i) + '章结束')
list=[4,5,6,8,15,16,17]
# 检查未看的视频,进行第二批视频
for i in list:
go(i,username,pwd)
3.运行脚本
首先在命令行安装selenium,记得敲回车
pip install selenium
然后运行我们的脚本,控制台敲python 空格 把脚本拖进控制台就ok,之后回车运行(输入脚本的绝对路径也行)
python
运行效果
后续更新源码和进阶版
关于UI版本的建议先参考下边这篇文章
一个简单的exe程序
本脚本不保证所有电脑都能正常使用。
如果对你有帮助可以打赏一波作者