网络剪贴板
刷新
复制
from selenium.common import NoSuchElementException from selenium.webdriver import Edge from selenium.webdriver.edge.service import Service from selenium.webdriver.edge.options import Options from selenium.webdriver.common.by import By from time import sleep from threading import Thread optionsJson = { 'request_interceptor': lambda request: None } options = Options() options.add_experimental_option("detach", True) driver=Edge(service=Service(), options=options) driver.get("https://onlineweb.zhihuishu.com/onlinestuh5") un='账号' p='密码' def extract(s): return s un=extract(un) p=extract(p) def inputUserInfo(): global un,p try: username=driver.find_element(By.XPATH,'/html/body/div[8]/div/form/div[1]/ul[1]/li[1]/input[4]') pwd=driver.find_element(By.XPATH,'/html/body/div[8]/div/form/div[1]/ul[1]/li[2]/input') loginBtn = driver.find_element(By.XPATH, '/html/body/div[8]/div/form/div[1]/span') username.send_keys(un) pwd.send_keys(p) loginBtn.click() except: sleep(0.5) inputUserInfo() def clickCourse(): try: course=driver.find_element(By.XPATH,'/html/body/div[1]/section/div[2]/section[2]/section/div/div/div/div[2]/div[1]/div[2]/ul/div/dl/dt/div[1]/div[1]') course.click() except: sleep(1) clickCourse() def closeDialog(): try: closeBtn = driver.find_element(By.XPATH, "/html/body/div[1]/div/div[6]/div[2]/div[1]/i") closeBtn.click() except: sleep(1) closeDialog() def againstPop(): try: # driver.execute_script(""" # var videos = document.querySelectorAll('video'); # videos.forEach(v => v.playbackRate = 1.5); # """) opt=driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/div[1]/div[2]/div[1]/div/div[2]/div/div[1]/div/div/div[2]/ul/li[2]/div[2]") closeBtn = driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/div[1]/div[2]/div[1]/div/div[3]/span/div") opt.click() sleep(1) closeBtn.click() except Exception as e: print(e) sleep(3) againstPop() def clickVideo(): try: video=driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/div[1]/div[2]/div[2]/div/div[8]') video.click() except Exception as e: print(e) sleep(1) clickVideo() def t1(): inputUserInfo() clickCourse() closeDialog() while True: againstPop() sleep(3) clickVideo() sleep(10) def switchVideo(): try: current = driver.find_element(By.CSS_SELECTOR, ".clearfix.video.current_play") finish_icons = current.find_elements(By.CSS_SELECTOR, ".time_icofinish") if len(finish_icons) > 0: all_videos = driver.find_elements(By.CSS_SELECTOR, "li.clearfix.video") current_index = all_videos.index(current) if current_index + 1 < len(all_videos): next_video = all_videos[current_index + 1] next_video.click() else: print("刷课完成") sleep(1) clickVideo() except: sleep(3) switchVideo() def t2(): while True: switchVideo() sleep(3) if __name__ == '__main__': Thread(target=t1).start() Thread(target=t2).start()