title: convert html table to csv in python
body: <p>I'm trying to scrape a table from a dynamic page. After the following code (requires selenium), I manage to get the contents of the <code>&lt;table&gt;</code> elements.</p>
  
  <p>I'd like to convert this table into a csv and I have tried 2 things, but both fail:</p>
  
  <ul>
  <li><code>pandas.read_html</code> returns an error saying I don't have html5lib installed, but I do and in fact I can import it without problems.</li>
  <li><code>soup.find_all('tr')</code> returns an error <code>'NoneType' object is not callable</code> after I run <code>soup = BeautifulSoup(tablehtml)</code></li>
  </ul>
  
  <p>Here is my code:</p>
  
  <pre><code>import time
  from selenium import webdriver
  from selenium.webdriver.support.ui import WebDriverWait 
  from selenium.webdriver.common.keys import Keys
  import pandas as pd
  
  main_url = "http://data.stats.gov.cn/english/easyquery.htm?cn=E0101"
  driver = webdriver.Firefox()
  driver.get(main_url)
  time.sleep(7)
  driver.find_element_by_partial_link_text("Industry").click()
  time.sleep(7)
  driver.find_element_by_partial_link_text("Main Economic Indicat").click()
  time.sleep(6)
  driver.find_element_by_id("mySelect_sj").click()
  time.sleep(2)
  driver.find_element_by_class_name("dtText").send_keys("last72")
  time.sleep(3)
  driver.find_element_by_class_name("dtTextBtn").click()
  time.sleep(2)
  table=driver.find_element_by_id("table_main")
  tablehtml= table.get_attribute('innerHTML')
  </code></pre>