title: How to make Selenium script scrape additional urls after either end script or error?
body: <p>Im new to coding! I found a large part of this script in a github that seems inactive now. Basically this script is scraping reviews of only one Tripadvisor restaurant. Depending on number of pages (same restaurant) it has to scrape the script either finishes normally or gives the following error when there is no more next button:</p>
  <blockquote>
  <p>selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .//a[@class=&quot;nav next ui_button primary&quot;]</p>
  </blockquote>
  <p>I would like the script to continue on to another URL in case it is finished with first restaurant or gets error for no next button. Help me guys!</p>
  <pre><code>import sys
  import csv
  from selenium import webdriver
  import time
  path_to_file = &quot;entirereview.csv&quot;
  num_page = 12
  url = &quot;https://www.tripadvisor.com/Restaurant_Review-g187147-d23117361-Reviews-Ya_Bayte-Paris_Ile_de_France.html&quot;
  if (len(sys.argv) == 4):
      path_to_file = sys.argv[1]
      num_page = int(sys.argv[2])
      url = sys.argv[3]
  driver = webdriver.Firefox()
  driver.get(url)
  driver.find_element_by_id('_evidon-accept-button').click()
  driver.find_element_by_id('filters_detail_language_filterLang_ALL').click()
  csvFile = open(path_to_file, 'a', encoding=&quot;utf-8&quot;)
  csvWriter = csv.writer(csvFile)
  for i in range(0, num_page):
      time.sleep(3)
      driver.find_element_by_xpath(&quot;//span[@class='taLnk ulBlueLinks']&quot;).click()
      time.sleep(3)
      container = driver.find_elements_by_xpath(&quot;.//div[@class='review-container']&quot;)
      for j in range(len(container)):
          title = container[j].find_element_by_xpath(&quot;.//span[@class='noQuotes']&quot;).text
          date = container[j].find_element_by_xpath(&quot;.//span[contains(@class, 'ratingDate')]&quot;).get_attribute(&quot;title&quot;)
          rating = container[j].find_element_by_xpath(&quot;.//span[contains(@class, 'ui_bubble_rating bubble_')]&quot;).get_attribute(&quot;class&quot;).split(&quot;_&quot;)[3]
          review = container[j].find_element_by_xpath(&quot;.//p[@class='partial_entry']&quot;).text.replace(&quot;\n&quot;, &quot; &quot;)
          csvWriter.writerow([date, rating, title, review])
      driver.find_element_by_xpath('.//a[@class=&quot;nav next ui_button primary&quot;]').click()
  driver.close()
  </code></pre>