'selenium error ERROR:chrome_browser_main_extra_parts_metrics.cc(227)

here in code, the purpose is to scrap the URLs of the youtube channels the code runs and a window of chrome appears but as soon as it scroll at the end of the last video its throws an error :

from re import T
from selenium import webdriver
from selenium import webdriver 
from selenium.webdriver.chrome.service import Service
from bs4 import BeautifulSoup
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import pandas as pd

s=Service("C:\\Program Files (x86)\\chromedriver.exe")
driver=webdriver.Chrome(service=s)
url = 'https://www.youtube.com/c/MrPcWale/videos'



def scrape_youtube(url, n_videos):
    ends = round(n_videos/30)+1
    # PATH = 'C:\Program Files (x86)\chromedriver.exe'

    video_list = []
    # driver = webdriver.Chrome(PATH)
    driver.get(url)
    body = driver.find_element(By.TAG_NAME,"body")
    for _ in range(ends):
        body.send_keys(Keys.END)
        time.sleep(3)
    html = driver.page_source
    soup = BeautifulSoup(html, 'html.parser')
    videos = soup.findAll('div', {'id': 'dismissable'})
    for video in videos:
        video_dict = {}
        video_dict['title'] = video.find('a', {'id': 'video-title'}).text
        video_dict['video_url'] = 'https://www.youtube.com/' + video.find('a', {'id': 'video-title'})['href']
        meta = video.find('div', {'id': 'metadata-line'}).findAll('span')
        video_dict['views'] = meta[0].text
        video_dict['video_age'] = meta[1].text
        video_list.append(video_dict)
    youtube_df = pd.DataFrame(video_list)
    youtube_df.to_csv('list.csv', index=True)
    print(youtube_df.head())


scrape_youtube(url, n_videos=302)

ERROR!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source