title: Python Selenium - Scraping a Table from a Dynamic Page
body: <p>I'm completely new to Python. I want to scrape data from a html table and put it into MS Excel. The website I'm scraping from is dynamic, so I have to select options from 3 drop down boxes to build the table.</p>
  <p>Please note that the code below gets me to the website and selects the options I need to build the table.</p>
  <p>Please note that the url of this site does not change. It stays the same as the drop down options are selected.</p>
  <p>This is what the table looks like once I select the options I need:</p>
  <p><a href="https://i.stack.imgur.com/tJHTc.png" rel="nofollow noreferrer">Table</a></p>
  <p>Here is a sample of the html for the table:</p>
  <p><a href="https://i.stack.imgur.com/7uaeF.png" rel="nofollow noreferrer">Sample HTML of Table</a></p>
  <p>My question is on how to read the table with Python and bring the header and contents of the table neatly into MS Excel. The preference would be to maintain the formatting (the font, alternating colors, etc) if possible, but that's not super important.</p>
  <p>This is the code I'm using to go to the website and select the options I need from the drop down boxes:</p>
  <pre><code>from selenium import webdriver
  DRIVER_PATH = 'path to chrome driver'
  from selenium.webdriver import chrome
  from selenium.webdriver.support.select import Select
  driver = webdriver.Chrome(executable_path='path to chrome driver')
  
  #open page
  driver.get('url of web page')
  
  #Select drop down box 1 option 
  select = Select(driver.find_element_by_id('cboGroup'))
  select.select_by_visible_text('Drop down box 1 option')
  
  #Insert wait
  import time
  time.sleep(1)
  #driver.implicitly_wait(10000)
  
  #Select drop down box 2 option
  select = Select(driver.find_element_by_id('cboElements'))
  select.select_by_visible_text('Drop down box 2 option')
  
  #Insert wait
  import time
  time.sleep(1)
  
  #Select drop down box 3 option
  import datetime
  from pandas.tseries.offsets import BDay
  ReportDate = datetime.datetime.today() - BDay(1)
  NewReportDate = ReportDate.strftime(&quot;%m/%d/%Y&quot;)
  print(NewReportDate)
  select = Select(driver.find_element_by_id('cboDelDate'))
  select.select_by_visible_text(NewReportDate)
  
  #Insert wait
  import time
  time.sleep(1)
  </code></pre>
  <p>I've tried using the send keys command to copy/paste the whole page into MS Excel (Ctrl+A, Ctrl+V) but the formatting gets thrown off and it doesn't look right.</p>
  <p>I've also tried using Pandas, but I haven't been able to grab the table data.</p>