e.g.
This is the code used to scrape title and views from a specific channel.
videos = driver.find_elements_by_class_name("style-scope ytd-grid-renderer")
from selenium import webdriver
driver.get("url")
driver.implicitly_wait(10)
videos = driver.find_elements_by_class_name("style-scope ytd-grid-renderer")
for video in videos:
title = videos.find_elements_by_xpath('.//*[@id="video-title"]')
views = videos.find_elements_by_xpath('.//*[@id="metadata-line"]/span[1]')
item = {
'title' : title,
'views' : views
}
Error displayed in terminal:
title = videos.find_elements_by_xpath('.//*[@id="video-title"]')
AttributeError: 'list' object has no attribute 'find_elements_by_xpath'
When using findElement() function in selenium, it is only valid when its driver.find_elements_by_xpath, and not when driver is replaced with a variable. (videos.find_elements_by_xpath)
Bit of a beginner, so there might be concepts I'm missing here. I am aware of [this post] and the solution provided, but it's solution did not seem to work and was quite confusing.
If there is a concept that should be learned to solve this problem, please some resources or explanations if you can. Thank you very much