part 2 - scrape data from html elements

2 -

to scrape elements, we need to wait for elements to load,

import WebDriverWait and By and the expected_conditions as EC

Then. target the html with By.((CSS_SELECTOR

import time
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

driver = webdriver.Chrome()
driver.get('https://sandbox.oxylabs.io/products')

WebDriverWait(driver,10).until(
    EC.presence_of_all_elements_located((By.CSS_SELECTOR, '.product-card'))
)

results = []

cards = driver.find_elements(By.CSS_SELECTOR,".product-card")
for card in cards:
    title = card.find_element(By.CSS_SELECTOR,".title").text.strip()
    price = card.find_element(By.CSS_SELECTOR,".price-wrapper").text.strip()
    results.append(
        {
        "title":title,
        "price": price,
        }
    )
print(results)

time.sleep(1)
driver.quit()