I'm trying to scrape data from the URL, but when I use the method find_elemnts()
I get this error. I am trying to get some data. Here is my code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
#opening the browser
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.bestbuy.com/")
#sending a request through the search bar
search = driver.find_element(By.NAME, 'st')
search.send_keys("dell xps")
search.send_keys(Keys.RETURN)
driver.maximize_window() # For maximizing window
driver.implicitly_wait(20) # gives an implicit wait for 20 seconds
#clicking a desired link by the class name
# driver.find_element(By.CLASS_NAME,'sku-title').click()
# paths:
# sku-title #class name for href links
# //*[@id="main-results"]/ol/li[1] #link class
# //*[@id="shop-sku-list-item-23022673"]/div/div/div[1]/div[3]/div[1]/div[1]/span[2] class name: sju-value #model
# //*[@id="pricing-price-23825371"]/div/div/div/div/div[1]/div/div[1]/div class name:priceView-hero-price priceView-customer-price #price
links = driver.find_elements(By.CLASS_NAME, 'sku-title')
for link in links:
# href = link.find_element(By.XPATH, './/*[@id="main-results"]/ol/li[1]').text
model = link.find_element(By.CLASS_NAME, 'sku-value').text
# price = link.find_element(By.XPATH, './/*[@id="pricing-price-23825371"]/div/div/div/div/div[1]/div/div[1]/div').text
print(model)
time.sleep(200)
driver.quit()
Expecting the data in a text (price, model and the links)