D 旗飘飘初衷甚好 二十小时营养够料 点击确认你人没跑 频繁弹窗怕你溜号 发展对象一脸苦笑 只想快快拉进度条
提示: 1.ios端可以熄屏直拉进度条 2.参考H5 video 标签视频播放进度跳转,一行代码就可实现视频跳转 3.然而楼主这两条都没想到,用了最蠢的办法,只能实现流畅播放出现弹窗自动点击
python代码
import threading
import multiprocessing
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver import ChromeOptions, ActionChains
import time
xpaths = [
"/html/body/div/div[2]/div[2]/div[2]/div/div[3]/div/div[2]/div[2]/a"
]
button_xpath = "//*[@id='wrapper']/div/button"
i_know_xpath = "/html/body/div[5]/div[3]/a"
i_know_finish_xpath = "//div[@class='public_cont public_cont1']"
i_know_finish_text_xpath = i_know_finish_xpath + "/div[2]/p[1]"
form_begining_xpath = "/html/body/div[4]/div[3]/a[1]"
catagorys_xpath = "/html/body/div[1]/div[2]/div[4]/ul"
loc = ("xpath", "//*[@class='public_submit']")
def pachong(user,pwd,url):
url2 = url + "/user/lesson"
option = ChromeOptions()
option.add_argument("headless")
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get(url)
time.sleep(1)
driver.find_element_by_xpath("//*[@id='app']/div/div[2]/div[3]/div/div[1]/input").send_keys(user)
driver.find_element_by_xpath("//*[@id='app']/div/div[2]/div[3]/div/div[2]/input").send_keys(pwd)
driver.implicitly_wait(10)
time.sleep(10)
for xpath in xpaths:
driver.get(url2)
time.sleep(1)
driver.implicitly_wait(10)
driver.find_element_by_xpath(xpath).click()
time.sleep(1)
index = 0
lis = driver.find_element_by_xpath("//div[@class='video_lists']/ul").find_elements_by_tag_name('li')
for object in lis:
index = index + 1
object_xpath = "//div[@class='video_lists']/ul" + "/li[" + str(index) + " ]/a"
element = driver.find_element_by_xpath(object_xpath)
driver.execute_script("arguments[0].click();", element)
video = driver.find_element_by_tag_name('video')
try:
while( 1 ):
try:
print(driver.find_element_by_xpath(i_know_finish_text_xpath).text)
except:
print("找不到对象")
break
if( driver.find_element_by_xpath(i_know_finish_text_xpath).text == "当前视频播放完毕!"):
i_know(driver)
break
i_know(driver)
driver.execute_script("return arguments[0].play()", video)
WebDriverWait(driver, 1000, 5).until(EC.presence_of_element_located(loc))
except:
print("无弹窗")
print(time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime()))
print(object)
def i_know(driver):
loc = ("xpath","//a[@class='public_submit']")
try:
e = WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located(loc))
e.click()
print("确认弹窗")
except:
print("没有弹窗")
if __name__ == '__main__':
user = "用户名"
pwd = "密码"
url = "学校党旗飘飘首页链接"
pachong(user,pwd,url)
不关心代码的话,只要把下面图里的user、pwd改成自己的,url改成学校发你们的链接! 再把“我的课程”里每个视频的xpath放到xpath这个数组里就好,长这样
|