0

I am trying to count total product on an amazon page i.e. "https://www.amazon.com/s?k=irobot+roomba" using python and selenium.

I have facing problems with these two lines

list_product_on_page=browser.find_element_by_xpath('//[@id="search"]/div[1]/div[2]/div/span[3]/div[2]/div') 
list_product_on_page.size

This is what I tried.. enter image description here I want to count total product in this single page.

enter image description here

this is the code I tried so far

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222

2 Answers2

0

To print the count of the products you can use either of the following Locator Strategies:

  • Using css_selector:

    print(len(driver.find_elements_by_css_selector("div.a-section img[src^='https://m.media-amazon.com/images']")))
    
  • Using xpath:

    print(len(driver.find_elements_by_xpath("//div[contains(@class, 'a-section')]//img[starts-with(@src, 'https://m.media-amazon.com/images')]")))
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-1

If you want to count products on page you can do:

list_product_on_page = browser.find_elements_by_css_selector('div.s-result-item.s-asin') 
print(len(list_product_on_page))
JaSON
  • 4,843
  • 2
  • 8
  • 15