title: PYTHON : How repeat task?
body: <p>I'm trying to scrape a page with lazy loading, so I use below codes, the same lines of codes needs to be repeated 4 to 5 times to all products listed/loaded. </p>
  
  <p>How do you simplify this codes so I don't have to repeat my codes  ?</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.chrome.options import Options
  import time
  
  driver.get("https://www.tropicanawholesale.com/shop-by-category/diet-and-weight-management/")
  driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  time.sleep(15)
  driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  time.sleep(15)
  driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  time.sleep(15)
  driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  
  elem = driver.find_elements_by_class_name("product-listing-row")
  raw_data = []
  for ii in elem:
      pname = ii.find_element_by_class_name('product-name').text
      print('pname: ' + pname)
      psku = ii.find_element_by_class_name('product-code').text
      print('psku: ' + psku)
      thumb = ii.find_element_by_class_name('scaleAll').get_attribute('src')
      print('thumb: ' + thumb)
      link = ii.find_element_by_css_selector('a').get_attribute('href')
      print('address: ' + link)
      raw_data_elem = {'Product_Name': pname,
          'Product_SKU': psku,
          'Product_ImageURL': thumb,
          'Product _URL': link}
      #add row to list
      raw_data.append(raw_data_elem)
      df = pd.DataFrame(raw_data, columns = ['Product_Name', 'Product_SKU',
          'Product_ImageURL', 'Product _URL'])
      df.to_csv (r'/Users/reezalaq/PycharmProjects/wholesale/data.csv')
  
  </code></pre>