Skip to content Skip to sidebar Skip to footer

Scraper Clicking On The Same Link Cyclically?

I've written some script in python using selenium to scrape name and price of different products from redmart website. My target is to click on each category among 10 in the upper

Solution 1:

You can implement simple counter that will allow you to iterate through list of categories as below:

counter = 0

while True:

    try:
        wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "li.image-facets-pill")))
        driver.find_elements_by_css_selector('img.image-facets-pill-image')[counter].click()      
        counter += 1    
    except IndexError:
        break  

    for elems in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "li.productPreview"))):
        name = elems.find_element_by_css_selector('h4[title] a').text
        price = elems.find_element_by_css_selector('span[class^="ProductPrice__"]').text
        print(name, price)

    driver.back()

driver.quit() 

Post a Comment for "Scraper Clicking On The Same Link Cyclically?"