Skip to content Skip to sidebar Skip to footer

How To Scroll To The End Of A Page Slowly Using Selenium So That I Can Get Dynamically Loaded Content

On a personal project am working on am in a situation where i need to scrape names of items from a dynamic site using selenium. In order to get all the data you need to scroll to

Solution 1:

Solution

 page = driver.find_element_by_tag_name("html")
 page.send_keys(Keys.END)

How its applied in this situation

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--window-size=1420,1080')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(chrome_options=chrome_options)

url = 'https://shopzetu.com/search?type=product,article,page&q=dress'
driver.get(url)

WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.XPATH, "//button[text()='No thanks']"))).click()
page = driver.find_element_by_tag_name("html")
page.send_keys(Keys.END)
products = driver.find_elements_by_class_name("grid-product__content")
for product in products:
    name = product.find_element_by_class_name("grid-product__title").text
    print(name)
page.send_keys(Keys.END)

Post a Comment for "How To Scroll To The End Of A Page Slowly Using Selenium So That I Can Get Dynamically Loaded Content"