from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from time import sleep
from selenium.webdriver.common.by import By
path = r'C:\Users\.wdm\drivers\chromedriver\win32\108.0.5359\chromedriver.exe'
# open the browser
# browser = webdriver.Chrome(executable_path=path)
s=Service(r'C:\Users\.wdm\drivers\chromedriver\win32\108.0.5359\chromedriver.exe')
browser = webdriver.Chrome(service=s)
# load the webpage
browser.get('https://www.amazon.in')
browser.maximize_window()
# get the input elements
input_search = browser.find_element(By.ID,'twotabsearchtextbox')
search_button = browser.find_element(By.XPATH,"(//input[@type='submit'])[1]")
# send the input to the webpage
input_search.send_keys("Smartphones under 10000")
sleep(1)
search_button.click()
products = []
for i in range(10):
print('Scraping page', i+1)
product = browser.find_elements(By.CLASS_NAME,'a-size-medium a-color-base a-text-normal')
for p in product:
products.append(p.text)
next_button = browser.find_element(By.CLASS_NAME,'a-last')
next_button.click()
sleep(3)
print(len(products))
products[:5]
brower.quit()
Above is the code to scrape the data from pages, and display the total count as well as product names. But this code isn't displaying the scraped data, what might be the issue?
Here is the Output:
Scraping page 1
Scraping page 2
Scraping page 3
Scraping page 4
Scraping page 5
Scraping page 6
Scraping page 7
Scraping page 8
Scraping page 9
Scraping page 10
0
Process finished with exit code 0
That's it, no count nothing.