0

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?

Rasedul Islam
  • 77
  • 1
  • 9
  • i try your code in my environment and work well can you sumbit the whole error log to figure out what is the problem . – kareem alkoul Feb 21 '22 at 23:16
  • 1
    This is the whole error log in pycharm https://i.ibb.co/QXFwYmM/Screenshot-517.png – Rasedul Islam Feb 22 '22 at 03:36
  • @kareemalkoul Hello there is any solution for this problem? – Rasedul Islam Feb 23 '22 at 04:10
  • thanks for your patience for the late answer,the cause of problem because your geckodriver.exe isn't in PATH. first if you didn't download the executable file ,download it from the repo in this url https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/ depend on your os type and your broswer. second add the path of executable file to PATH in enviroment variables,see this link to know how to add to PATH https://stackoverflow.com/questions/9546324/adding-a-directory-to-the-path-environment-variable-in-windows – kareem alkoul Feb 24 '22 at 13:11

0 Answers0