title: Pandas: Repeat function for current keyword if except
body: <p>I have built a web scraper. The program enters searchterm into a searchbox and grabs the results. <code>Pandas</code> goes through a spreadsheet line-by-line in a column to retrieve each searchterm.</p>
  
  <p>Sometimes the page doesn't load properly, prompting a refresh.</p>
  
  <p>I need a way for it to repeat the function and try the <em>same</em> searchterm if it fails. Right now, if I <code>return</code>, it would go on to the next line in the spreadsheet.</p>
  
  <pre><code>import pandas as pd
  from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  
  df = pd.read_csv(searchterms.csv, delimiter=",")
  
  def scrape(searchterm):
      #Loads url
      searchbox = driver.find_element_by_name("searchbox")
      searchbox.clear()
      searchbox.send_keys(searchterm)
      print "Searching for %s ..." % searchterm
  
      no_result = True
      while no_result is True:
          try:
              #Find results, grab them
              no_result = False
          except:
              #Refresh page and do the above again for the current searchterm - How?
              driver.refresh()
      return pd.Series([col1, col2])
  
  df[["Column 1", "Column 2"]] = df["searchterm"].apply(scrape)
  #Executes crawl for each line in csv
  </code></pre>