自动播放视频并录屏保存的python脚本

自动播放视频并录屏保存的python脚本,第1张

概述`fromtimeimportsleepfromseleniumimportwebdriverfromselenium.webdriver.firefox.webdriverimportWebDriverfromselenium.webdriver.support.uiimportSelect,WebDriverWaitfromselenium.webdriver.supportimportexpected_conditionsasECfromseleniu

`from time import sleep
from selenium import webdriver
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support.ui import Select, webdriverwait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import pyautogui
import pyperclip

driver = webdriver.firefox()

打开网页

driver.get('https://www.luffycity.com/')

登录窗口最大化

driver.maximize_window()

先关闭广告d窗,

driver.find_element_by_xpath('/HTML/body/div[1]/div/div/div[2]/div/img[1]').click()

然后点击登录按钮

webdriverwait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, '/HTML/body/div[1]/div/div/header/div/div/div[2]/div[2]/span')))
driver.find_element_by_xpath('/HTML/body/div[1]/div/div/header/div/div/div[2]/div[2]/span').click()

输入用户名,密码

driver.find_element_by_xpath('/HTML/body/div[1]/div/div/div[2]/div/div[2]/div[1]/div[1]/input').clear()
driver.find_element_by_xpath('/HTML/body/div[1]/div/div/div[2]/div/div[2]/div[1]/div[1]/input').send_keys('username')
driver.find_element_by_xpath('/HTML/body/div[1]/div/div/div[2]/div/div[2]/div[1]/div[2]/input').clear()
driver.find_element_by_xpath('/HTML/body/div[1]/div/div/div[2]/div/div[2]/div[1]/div[2]/input').send_keys(
'password')

点击登录

driver.find_element_by_xpath('/HTML/body/div[1]/div/div/div[2]/div/div[2]/button').click()
sleep(3)

打开一个课程链接

driver.get('https://www.luffycity.com/play/13735')

循环下面的步骤

def record_screen(count):
for i in range(count):
# 点击一次刷新按钮
driver.refresh()
# 当全屏按钮出现时,点击全屏按钮,
webdriverwait(driver, 10).until(EC.visibility_of_element_located(
(By.XPATH, '/HTML/body/div[1]/div/div/div/div[1]/div[2]/div/div/div[2]/div[2]/div[2]/div[8]/button')))
driver.find_element_by_xpath(
'/HTML/body/div[1]/div/div/div/div[1]/div[2]/div/div/div[2]/div[2]/div[2]/div[8]/button').click()
# 点击开始
driver.find_element_by_xpath('/HTML/body/div[1]/div/div/div/div[1]/div[2]/div/div/div[1]/div[4]/span').click()
# 通过快捷键ctrl+F1开始录屏,用autoit切换到浏览器
pyautogui.hotkey('ctrl', 'F1')
# 等待5s,查询下面的h5的名称,并copy,

1.313 第89天:Flask初始化配置
sleep(5)
vIDeo_name = driver.find_element_by_xpath("//div[@class='section active']/section/h5").get_attribute(
'textContent')
vIDeo_name_postfix = vIDeo_name + '.wmv'
pyperclip.copy(vIDeo_name_postfix)
# 每过10s检查一次pv-time-current时间,如果pv-time-current时间=pv-time-duration,通过快捷键ctrl+F2结束录屏,并退出while循环
# 00:21,38:44
while True:
pv_time_current = driver.find_element_by_class_name("pv-time-current").get_attribute('textContent')
pv_time_duration = driver.find_element_by_class_name("pv-time-duration").get_attribute('textContent')
if pv_time_current == pv_time_duration:
print('视频播放完成:', vIDeo_name_postfix)
pyautogui.hotkey('ctrl', 'F2')
break
else:
sleep(10)
# paste上面copy的名称+wmv后缀,用autoit切换到浏览器,按ESC退出全屏
sleep(2)
pyautogui.hotkey('ctrl', 'v')
pyautogui.hotkey('enter')
pyautogui.hotkey('alt', 'tab')
sleep(1)
pyautogui.hotkey('esc')
sleep(1)
# 检查是否有反馈d窗,如果有就点击关闭按钮,
pop_window_Feedback = '/HTML/body/div[1]/div/div/div/div[1]/div[3]/div/p[1]/img'
pop_window_next = '/HTML/body/div[1]/div/div/div/div[1]/div[3]/button'
try:
# driver.find_element_by_xpath(pop_window_Feedback)
driver.find_element_by_xpath(pop_window_Feedback).click()
driver.find_element_by_xpath(pop_window_next).click()
except:
# 如果没有反馈d窗,就点击下一节按钮,
driver.find_element_by_xpath(pop_window_next).click()
# count减1
# count -= 1
print(i)

record_screen(200)
`

总结

以上是内存溢出为你收集整理的自动播放视频并录屏保存的python脚本全部内容,希望文章能够帮你解决自动播放视频并录屏保存的python脚本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1188882.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存