I am trying to collect the ASIN of products from Amazon.in webpage.I have the code which will open a web driver and search for a product name and navigate to the first page of the product page.It is able to collect the data only for the first page,but how to move to the next page to collect same data. here is my code :
import time
import json
import re
import numpy as np
from bs4 import BeautifulSoup
from selenium import webdriver
import urllib.request
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
import pandas as pd
temp = []
def init_driver():
driver = webdriver.Chrome(executable_path = "C:\\Users\\Desktop\\chromedriver")
driver.wait = WebDriverWait(driver, 10)
return driver
def get_asin(driver):
driver.get("https://www.amazon.in")
print ('Getting the URL')
HTML = driver.page_source
search_button = driver.find_element_by_id("twotabsearchtextbox")
search_button.send_keys("Mobiles")
select_button = driver.find_element_by_class_name("nav-input")
select_button.click()
HTML1=driver.page_source
soup = BeautifulSoup(HTML1, "html.parser")
styles = soup.find_all('li')
#print(styles)
#print(type(styles))
ASIN=[]
for link in styles:
if link.has_attr('data-asin'):
ASIN.append(link['data-asin'])
return(ASIN)
#print(ASIN)
if __name__ == "__main__":
driver = init_driver()
ASIN_NO = get_asin(driver)
#time.sleep(3)
#print ('opening search page')
#for i in range(0,len(ASIN_NO)):
#scrape(driver,ASIN_NO[i])
print (ASIN_NO)
time.sleep(5)
I have tried the both the following syntax which shows the errors :
select_button = driver.find_element_by_id('pagnNextString')
select_button.click()
Exception in logs:
WebDriverException: Message: unknown error: Element ... is not clickable at point (778, 606). Other element would receive the click:
select_button = driver.find_element_by_class_name('srSprite pagnNextArrow')
select_button.click()
InvalidSelectorException: Message: invalid selector: Compound class names not permitted
please help with the correct way. Thanks in advance.