selenium webdriver – i want to load full page of a ecommerce website
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Set up the WebDriver
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()
driver.get("https://alaneesqatar.qa/product-tag/honor/")
time.sleep(5) # Wait for the page to load
# Scroll to the bottom of the page to load more content
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(3) # Wait for new content to load
# Click the "Load More" button until all products are loaded
while True:
try:
load_more_button = driver.find_element(By.ID, "load-more")
driver.execute_script("arguments[0].click();", load_more_button)
time.sleep(3) # Wait for new products to load
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(3) # Wait for new content to load
except:
print("No more 'Load More' button found or an error occurred.")
break # Exit the loop if no more "Load More" button is found
Read more here: Source link
