Aug-04-2023, 12:43 PM
It seems that you are trying to extract links from the given URL using Selenium and the Chrome WebDriver. However, there are some issues in the way you are trying to locate the elements.
Use By.CSS_SELECTOR to locate the elements by the CSS selector. The class 'css-1wbmdb2' seems to be the correct class that contains the links.Then find all anchor elements (links) within this class and extract their 'href' attribute to get the URLs.
Here is have updated your code:-
Use By.CSS_SELECTOR to locate the elements by the CSS selector. The class 'css-1wbmdb2' seems to be the correct class that contains the links.Then find all anchor elements (links) within this class and extract their 'href' attribute to get the URLs.
Here is have updated your code:-
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By url = 'https://www.arte.tv/fr/videos/RC-019798/electro-chillout/' options = Options() options.add_argument("--headless") driver = webdriver.Chrome(options=options) driver.get(url) # Find all anchor elements within the specific class 'css-1wbmdb2' links = driver.find_elements(By.CSS_SELECTOR, '.css-1wbmdb2 a') # Extract and print the href attribute of each link for link in links: href = link.get_attribute('href') print(href) driver.quit()