I would like to write a code that would make Python scrape some data on a page, then click on the \"next\" button at the bottom of the page, scrape some data on the second p
I would make an endless while True
loop and break it once there is TimeoutException
thrown - this would mean there are no pages to go left:
wait = WebDriverWait(driver, 10)
while True:
# grab the data
# click next link
try:
element = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'reviews_pagination_link_nav')))
element.click()
except TimeoutException:
break
For this to work, you need to make sure that once you hit the last page, the element with class="reviews_pagination_link_nav"
is not on the page or is not clickable.