Ai
1 Star 0 Fork 1

jack2583/PythonExamples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
get_youtube_view.py 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
"""
Created on Thu Apr 27 16:28:36 2017
@author: barnabysandeford
"""
# Currently works for Safari, but just change to whichever
# browser you're using.
import time
# Added pafy to get video length for the user
import pafy
# Changed the method of opening the browser.
# Selenium allows for the page to be refreshed.
from selenium import webdriver
# adding ability to change number of repeats
count = int(input("Number of times to be repeated: "))
# Same as before
url = input("Enter the URL : ")
refreshrate = None
# tries to get video length using pafy
try:
video = pafy.new(url)
if hasattr(video, 'length'):
refreshrate = video.length
# if pafy fails to work, prints out error and asks for video length from the user
except Exception as e:
print(e)
print("Length of video:")
minutes = int(input("Minutes "))
seconds = int(input("Seconds "))
# Calculating the refreshrate from the user input
refreshrate = minutes * 60 + seconds
# Selecting Safari as the browser
driver = webdriver.Safari()
if url.startswith("https://"):
driver.get(url)
else:
driver.get("https://" + url)
for i in range(count):
# Sets the page to refresh at the refreshrate.
time.sleep(refreshrate)
driver.refresh()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jack2583/pythonExamples.git
git@gitee.com:jack2583/pythonExamples.git
jack2583
pythonExamples
PythonExamples
master

搜索帮助