发文章
发文工具
撰写
网文摘手
文档
视频
思维导图
随笔
相册
原创同步助手
其他工具
图片转文字
文件清理
AI助手
留言交流
整体代码如下:
#判断是否为视频 是就播放 不是就下一页操作 from selenium import webdriver import time browser = webdriver.Chrome(executable_path="D:\google\chromedriver.exe") url='http://passport2.chaoxing.com/wunitlogin?refer=http%3A%2F%2Fi.mooc.chaoxing.com' browser.get(url) #学校 学号 密码 验证码登陆 def login(): inp_1 = input("请输入学校:") inp_2 = input("请输入学号:") inp_3 = input("请输入密码:") inp_4 = input("请输入验证码:") school = browser.find_element_by_id("FidName") username = browser.find_element_by_id("idNumber") password = browser.find_element_by_id("pwd") verycode = browser.find_element_by_id("numcode") school.send_keys(inp_1) username.send_keys(inp_2) password.send_keys(inp_3) verycode.send_keys(inp_4) browser.find_element_by_xpath('//*[@id="userLogin"]/div/a').click() print("----------正在登陆中----------") # 进入主页 开始选择课程 xpath匹配 def html_1(): time.sleep(2) browser.find_element_by_xpath('//*[@id="zne_kc_icon"]').click() #课程选项的xpath print("----------进入课程----------") time.sleep(2) browser.switch_to.frame("frame_content") #选择我需要学的课的xpath browser.find_element_by_xpath('/html/body/div/div[2]/div[2]/ul/li[6]/div[2]/h3/a').click() #课程 print("----------已进入所点击课程----------") def html_2(): #浏览器标签页跳转设置 browser.switch_to.window(browser.window_handles[1]) #进入课程中的第一个小节 time.sleep(1) browser.find_element_by_xpath('/html/body/div[5]/div[1]/div[2]/div[3]/div[1]/div[1]/h3/span[3]/a').click() #开始小节 # button模拟点击播放 def button(): time.sleep(1) try: #进入frame播放框架 browser.switch_to.frame("iframe") browser.switch_to.frame(0) time.sleep(2) #此处等待需要就一些就不会报错终止程序 browser.find_element_by_xpath('//*[@id="video"]/button').click() print('----------等待播放----------') time.sleep(2) print("----------课程正在播放中----------") except: # 回到主框架 browser.switch_to.default_content() print("----------此处不是视频,即将点击下一页----------") time.sleep(4) browser.find_element_by_xpath('//*[@id="mainid"]/div[1]/div[2]').click() time.sleep(4) #判断完重新回到button函数再进行判断 button() #判断视频是否播放完 def vedio_if(): time.sleep(1) try: vedio_stat_time = browser.find_element_by_xpath('//*[@id="video"]/div[4]/div[2]/span[2]').get_attribute("textContent") vedio_end_time = browser.find_element_by_xpath('//*[@id="video"]/div[4]/div[4]/span[2]').get_attribute("textContent") print("播放时间:",vedio_stat_time,'结束时间:',vedio_end_time) time.sleep(1) return vedio_stat_time,vedio_end_time except: pass # 判断有第二节课吗有就播放 def vedio_if2(vedio_stat_time,vedio_end_time): if vedio_stat_time ==vedio_end_time: try: browser.switch_to.default_content() browser.switch_to.frame("iframe") browser.switch_to.frame(1) browser.find_element_by_xpath("//*[@id='video']/button").click() time.sleep(2) except: print("----------没有第二节课了,即将进入下一页----------") def next_start(vedio_stat_time,vedio_end_time): if vedio_stat_time==vedio_end_time: try: browser.switch_to.default_content() print("----------开始点下一页----------") time.sleep(1) browser.find_element_by_xpath('//*[@id="mainid"]/div[1]/div[2]').click() time.sleep(2) except: print("----------结束----------") if __name__=='__main__': login() html_1() html_2() while True: button() time_tuple = vedio_if() while time_tuple[0] != time_tuple[1]: time_tuple = vedio_if() try: vedio_if2(time_tuple[0],time_tuple[1]) if time_tuple[0] ==time_tuple[1]: print("----------开始测试第二节课时间----------") time_tuple_2 = vedio_if() while time_tuple_2[0] !=time_tuple_2[1]: time_tuple_2 = vedio_if() next_start(time_tuple_2[0],time_tuple_2[1]) except: next_start(time_tuple[0],time_tuple[1])
源代码参照文章:https://www.cnblogs.com/xhfzjbs/p/12028948.html
来自: wenxuefeng360 > 《待分类1》
0条评论
发表
请遵守用户 评论公约
遇到只有点击一下验证码的空白处,才会出现验证码,这种登录怎么解?
# 获取验证码图片,使用Tesseract-OCR识别captcha_img = browser.find_element_by_id("captcha_img")captcha_img.screenshot(...
python网银
browser.find_element_by_id(''''''''username'''''''').send_keys(param[''''''''username'&...
经验 | python 操作浏览器的三种方式
browser.find_element_by_xpath(''''''''//input[@class=''''''''fm...
Python | selenium 的基本操作
Selenium2 python自动化36-判断元素存在
Selenium2 python自动化36-判断元素存在。# 判断页面上有无id为kw的元素if is_element_exist(''#kw''): driver.find...
从零开始Web自动化(四):如何过打字网站的作弊检测,从而实现排行榜第一
一、分析和解决思路 上篇博文中,我们的程序被检测出作弊了,那如何过检测呢?思路: 我们打的太快了,完全超出了人类的极限。那我们要...
轻松自动化---selenium-webdriver(python)
轻松自动化---selenium-webdriver(python)下面看看python 穿上selenium webdriver 是多么的性感:browser.get(http://www.baidu.com)browser.find_element_by_id("kw").send_keys("sele...
python3 爬虫学习: 自动给你心上人的微博点赞
user_name = browser.find_element_by_css_selector(''''''''#loginName'''''...
selenium2+phantomjs入门范例
selenium2+phantomjs入门范例。#coding=utf-8from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium...
微信扫码,在手机上查看选中内容