-1

Here is the code i use

import os
import uuid
import time
from selenium.webdriver import *
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.keys import Keys

#########################################################################################################################################################################
# Mettre ici la requeste qui commence le scrapping
channel = "https://www.youtube.com/c/TsodingDaily/videos"
# Headless : True or False
headless = False
#########################################################################################################################################################################

# Parametre du navigateur
Options = Options()
if headless : Options.add_argument("--headless")
#s = Service("drivers\\geckodriver.exe",0,None,"drivers\\geckodriver.log")
#driver = Firefox(service=s, options=Options)
driver = Firefox(options=Options)

driver.get(channel)
driver.find_element(By.XPATH, "/html/body/c-wiz/div/div/div/div[2]/div[1]/div[4]/form/div/div/button/span").click()
#l = driver.find_elements(By.CLASS_NAME, "style-scope ytd-grid-video-renderer")
l = driver.find_elements(By.CLASS_NAME, "yt-simple-endpoint inline-block style-scope ytd-thumbnail")
print(l)

I dont understand why when i use the class name "yt-simple-endpoint inline-block style-scope ytd-thumbnail" i get nothing but the same code is working with "style-scope ytd-grid-video-renderer"

can you help me ?

  • Did you read the error message you got when you tried this? What does it say? You should always add the error text to your question. – JeffC Jan 13 '22 at 04:08
  • Does this answer your question? [How to avoid Compound Class name error in Page Object?](https://stackoverflow.com/questions/17808521/how-to-avoid-compound-class-name-error-in-page-object) – JeffC Jan 13 '22 at 04:09

1 Answers1

0

You can't pass multiple classnames using:

driver.find_element(By.CLASS_NAME, "classname")

and doing so will result in Compound class names error as follows:

Message: invalid selector: Compound class names not permitted

To pass multiple classnames you can use either of the following Locator Strategies:

  • Using css_selector:

    l = driver.find_elements(By.CSS_SELECTOR, ".yt-simple-endpoint.inline-block.style-scope.ytd-thumbnail")
    
  • Using xpath:

    l = driver.find_elements(By.XPATH, "//*[@class='yt-simple-endpoint inline-block style-scope ytd-thumbnail']")
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • ok ill try this but i dont understand why ```l = driver.find_elements(By.CLASS_NAME, "yt-simple-endpoint inline-block style-scope ytd-thumbnail")``` is not working – VictorHugo Jan 12 '22 at 13:04
  • @VictorHugo Checkout the updated answer and let me know if you have further questions. – undetected Selenium Jan 12 '22 at 13:12
  • thanks a lot for your answers, this is a little bit clearer for me. Just one last question, why do i have a none in first element in my list each time ? – VictorHugo Jan 12 '22 at 13:48
  • possibly _`find_elements()`_ was to quick to collect the elements even before the first element was rendered or the first element may be an a hidden/invisible element. – undetected Selenium Jan 12 '22 at 14:13
  • Why are you answering a question that you know is a dup? – JeffC Jan 13 '22 at 04:09