title: Python fetch URL, open output file, write output, close output file, end for loop
body: <p>I have this below script which I used currently. I extract data from a website using multiple URLs in excel. I want to save extracted data in an excel file with each extraction.</p>
  <p>In Short, I need a program which</p>
  <ol>
  <li>Open Excel File</li>
  <li>Save extracted data in the last raw.</li>
  <li>Close the excel file.</li>
  </ol>
  <p>Currently, my code fetches the entire data first then paste data into a CSV file.
  Due to that, I am not able to extract information for more than 1000 links.</p>
  <p>Thanks</p>
  <pre><code>for item in exampleData:
      final.append(item[0])
      
  for url in final:
      driver.get(url)
      soup = BeautifulSoup(driver.page_source, 'html.parser')
      results = soup.find_all('div',{'id':'dp'})
  
      for item in results:
          record = extract_record(item)
          if record:
              records.append(record)
              
  driver.close()
  
  df = pd.DataFrame(records)
  df.columns = ['item_name', 'price_Final', 'Final_bullet','prod_desc','Image_link', 'Stock', 'Prod_spec ','Quantity_avail','Prod_spec','Brand_info','Add_info','Delivered_by','BTG']
  writer = ExcelWriter('Desktop/Data Scrap.xlsx')
  df.to_excel(writer,'Sheet1',index=False)
  writer.save()
  
  </code></pre>