日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

刷网课seleinum 小程序

發布時間:2023/12/31 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 刷网课seleinum 小程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

遇到的問題看的參考文章如下
知乎 selenium iframe處理
CSDN Selenium在定位的class含有空格的復合類的解決辦法
Python+Selenium筆記(九):操作警告和彈出框
Python3 錯誤和異常的使用
selenium之 玩轉鼠標鍵盤操作(ActionChains)
selenium 瀏覽器導航操作
根據ManicTime顯示,大約花了10小時左右

from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains import re import time studentId = ******* password = '*******' kaishi = '1.1' jieshu = '11.1' def logon(driver):driver.get(r'********')driver.find_element_by_class_name('loginBtn').click()driver.find_element_by_name('uname').send_keys(studentId)driver.find_element_by_name('password').send_keys(password)#input()#driver.switch_to.frame('frame_content')#driver.find_element_by_class_name('clearfix').click()#time.sleep(2)def enterCourse(driver,courseUrl):driver.get(courseUrl)def acquireUnits(driver,startId,endId): #獲取所刷課程url,返回一個列表units = driver.find_elements_by_class_name('units')unitsDict = {}a = 0for i in units:a = a+1z = 0print(i.text.split('\n')[0:2])for i_1 in i.find_elements_by_class_name('articlename'):z += 1unitsDict[f'{str(a)}.{str(z)}'] = i_1.find_element_by_tag_name('a').get_attribute('href')# 將課程鏈接放入字典中print(f'---{str(a)}.{str(z)}{i_1.text}')# 輸出目錄unitsId = list(unitsDict.keys())pickUnitsId = unitsId[unitsId.index(startId):unitsId.index(endId)+1]# 挑出所選課程的鍵pickUnitsObj = [unitsDict[i_2] for i_2 in pickUnitsId]return pickUnitsObjdef initStart(driver,url): #進入課程,讓視頻播放driver.get(url)for i in range(2,4):try:time.sleep(2)driver.switch_to.frame('iframe') #切換視頻frameiframe = driver.find_element_by_css_selector(".ans-attach-online.ans-insertvideo-online") #定位播放器位置driver.switch_to.frame(iframe) #切換播放器iframedriver.find_element_by_css_selector(".vjs-big-play-button").click() #點擊播放#paused = driver.find_element_by_xpath('//*[@id="video"]/div[4]/button[1]') #確定播放按鈕#ActionChains(driver).move_to_element(paused)time.sleep(3)driver.find_element_by_xpath('//*[@id="video"]/div[4]/button[1]').click()time.sleep(3)return driver.find_element_by_xpath('//*[@id="video"]/div[4]/div[4]/span[2]').textbreakexcept Exception as e:print(e)driver.get(url)time.sleep(1)driver.find_element_by_id(f'dct{i}').click()print("本頁非播放播放頁,切換")def test(driver): #破解測試題,目前只有判斷題try:for i in driver.find_elements_by_name("ans-videoquiz-opt"): #判斷題對錯元素i.click()driver.find_element_by_class_name('ans-videoquiz-submit').click() #提交答案元素time.sleep(1)try:driver.find_element_by_class_name('ans-videoquiz-submit').click()except Exception as e:if "Alert" == str(e).split(' ')[0]:driver.switch_to.alert.accept()else:print(e)except:passdef check(driver):try:if driver.find_element_by_xpath('//*[@id="video"]/div[4]/button[1]/span[2]').text == '播放':try:driver.find_element_by_xpath('//*[@id="video"]/div[4]/button[1]').click()#用于檢測是否在播放,如果無法點擊,判斷是否遇到題目return Falseexcept:test(driver)elif driver.find_element_by_xpath('//*[@id="video"]/div[4]/button[1]/span[2]').text == '重播':return Trueelse:return Falseexcept Exception as e: print(e)return Falsedef main():driver=webdriver.Chrome() logon(driver)enterCourse(driver,str(input('請輸入課程url:\n')))time.sleep(1)units = acquireUnits(driver,kaishi,jieshu)for i in units:try:allTime = initStart(driver,units[i])print(f'當前視頻時間:{allTime}')allTime = int(allTime[:2]) * 60 + int(allTime[-2:])while True:if check(driver):print("本視頻結束,進入下一個")breaktime.sleep(5)except:breakif __name__ == "__main__":driver=webdriver.Chrome() logon(driver)enterCourse(driver,str(input('請輸入課程url:\n')))time.sleep(1)units = acquireUnits(driver,kaishi,jieshu)for i in units:try:allTime = initStart(driver,units[i])print(f'當前視頻時間:{allTime}')allTime = int(allTime[:2]) * 60 + int(allTime[-2:])while True:if check(driver):print("本視頻結束,進入下一個")breaktime.sleep(5)except:break

總結

以上是生活随笔為你收集整理的刷网课seleinum 小程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。