Video description scrapping with Beautifulsoup

I’m trying to scrape a link in the video description on youtube, but the list always return empty.

I’ve tried to change the tag from where I’m scraping, but there is no change in either the output nor the error message.

Here’s the code I’m using:

from bs4 import BeautifulSoup
import requests

source = requests.get('').text

soup = BeautifulSoup(source, 'lxml')

link = [i['href'] for i in soup.findAll('a', class_='yt-simple-endpoint style-scope yt-formatted-string', href=True)]


What is wrong, and how can I solve it?


In your case, requests doesn’t return the whole HTML structure of the page. If Youtube is filling in the data using JavaScript we must run it through a real browser to get the source of the page, such as Chrome Headless using the Selenium library. Here is the general solution:

from bs4 import BeautifulSoup
from selenium import webdriver
import time

options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = options)
url = ""
soup = BeautifulSoup(driver.page_source, 'html.parser')

link = [i['href'] for i in'div#meta div#description [href]')]