Skip to content Skip to sidebar Skip to footer

Python Selenium Automatically Load More Pages

I am trying a scrap a website, 'www.jabong.com' here for each product line when we reach the bottom of the page it load more products. I want to scrap all the links. The code which

Solution 1:

Try this. It will fetch you required data.

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

link_list = ["https://www.jabong.com/women/clothing/trousers-jeans/trousers/?source=topnav_women",]

def fetch_links(link):
    chrome_options = Options()
    chrome_options.add_argument("--disable-notifications")
    driver = webdriver.Chrome(chrome_options=chrome_options)
    driver.get(link)
    actions = ActionChains(driver)
    for _ in range(10):   #Adjust this range according to your need, I meant how far you wanna go down.
        actions.send_keys(Keys.SPACE).perform()
        time.sleep(1)

    for item in driver.find_elements_by_css_selector(".h4"):
        print(item.text)

fetch_links(link_list[0])

Partial results:

W Orange Printed Palazzo
DOROTHY PERKINS Olive Solid Mid Rise Skinny Fit Coloured Pant
VARANGA White Solid Palazzo
VARANGA Blue Printed Palazzo

Post a Comment for "Python Selenium Automatically Load More Pages"