How do I get the video title and links of the videos on a youtube channel?
What I want is to build a web scraper with BeautifulSoup that extracts all the titles, views, dislikes and likes, comments and dates published from videos on a youtube channel.
The approach I'm using is to first extract the titles of the video ad URL then use the URL to get the details about the video.
So far I've not had any luck. below is a test url
url = 'https://www.youtube.com/c/AlexTheAnalyst/videos'
CodePudding user response:
Try this I have extract youtube videos these code help you:
from selenium import webdriver
PATH="C:\Program Files (x86)\chromedriver.exe"
url='https://www.youtube.com/channel/UC8tgRQ7DOzAbn9L7zDL8mLg'
driver =webdriver.Chrome(PATH)
driver.get(url)
videos = driver.find_elements_by_class_name("style-scope ytd-grid-video-renderer")
for video in videos:
title=video.find_element_by_xpath('.//*[@id="video-title"]').text
days= video.find_element_by_xpath('.//*[@id="metadata-line"]/span[2]').text
views= video.find_element_by_xpath('.//*[@id="metadata-line"]/span[1]').text
print(title,days,views)