I have some simple selenium scraping code that returns all the search results, but when I run the for loop, it displays an error: Message: invalid argument: 'url' must be a string
(Session info: chrome=93.0.4577.82)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
chrome_path = r'C:\Windows\chromedriver.exe'
driver = webdriver.Chrome(chrome_path)
driver.get("https://www.youtube.com/results?search_query=python+course")
user_data = driver.find_elements_by_xpath('//*[@id="video-title"]')
links = []
for i in user_data:
links.append(i.get_attribute('href'))
print(links)
wait = WebDriverWait(driver, 10)
for x in links:
driver.get(x)
v_id = x.strip('https://www.youtube.com/watch?v=')
#//*[@id="video-title"]/yt-formatted-string
v_title = wait.until(EC.presence_of_element_located(
(By.CSS_SELECTOR,"h1.title yt-formatted-string"))).text
I would like to ask for some help. How to avoid this error? Thanks.