I try to download all videos from a youtube channel
My Code:
from selenium import webdriver
from time import sleep
import time
from random import randint
import requests
from pytube import YouTube
#Open browser
driver = webdriver.Firefox()
#My youtube channel
url = "https://www.youtube.com/channel/UCS00N7QLjxzMJMAI_KLEqeQ"
#Get youtube video
def get_video_youtube(driver,url):
driver.get(url)
time.sleep(randint(5, 9))
driver.get(url+"/videos")
ht=driver.execute_script("return document.documentElement.scrollHeight;")
while True:
prev_ht=driver.execute_script("return document.documentElement.scrollHeight;")
driver.execute_script("window.scrollTo(0, document.documentElement.scrollHeight);")
time.sleep(2)
ht=driver.execute_script("return document.documentElement.scrollHeight;")
if prev_ht==ht:
break
links=driver.find_elements_by_xpath('//*[@id="video-title"]')
with open('f:\\somefile.txt', 'w') as the_file:
for link in links:
print(link.get_attribute("title"))
print(link.get_attribute("href"))
yt = YouTube(link.get_attribute("href"))
hd = yt.streams.get_highest_resolution()
hd.download("F:\\youtube1\\")
the_file.writelines(link.get_attribute("href")+'\n')
sleep(3)
get_video_youtube(driver,url)
#get_all_names(driver,url)
Saying This problem: selenium.common.exceptions.WebDriverException
It's not working, How can I download all videos from a youtube channel?