title: Converting html to excel in Python
body: <p>I'm trying to convert the table in the following site to an xls table:</p>
  
  <p><a href="http://www.dekel.co.il/madad-lazarchan" rel="nofollow">http://www.dekel.co.il/madad-lazarchan</a></p>
  
  <p>The following is the code I came up with from researching:</p>
  
  <pre><code>from bs4 import BeautifulSoup
  import pandas as pd
  from urllib2 import urlopen
  import requests
  import csv
  
  url='http://www.dekel.co.il/madad-lazarchan'
  table = pd.read_html(requests.get(url).text, attrs={"class" : "medadimborder"})
  
  print table&lt;/code&gt;
  </code></pre>
  
  <p>How can I get it to display the headers properly and output to a csv or xls file?</p>
  
  <p>If I add the following:</p>
  
  <pre><code>table.to_csv('test.csv')
  </code></pre>
  
  <p>instead of the print row I get this error: </p>
  
  <pre><code>'list' object has no attribute 'to_csv'
  </code></pre>
  
  <p>Thanks in Advance!</p>
  
  <p>Okay based on the comments maybe I shouldn't use panda or read_html as I want a table and not a list. I wrote the following code but now the printout has delimiters and looks like I lost the header row. Also still not sure how to export it to csv file.</p>
  
  <p><code>
      <code>from bs4 import BeautifulSoup 
      import urllib2 
      import csv
      soup = BeautifulSoup(urllib2.urlopen('http://www.dekel.co.il/madad-lazarchan').read(), 'html') 
      data = []
      table = soup.find("table", attrs={"class" : "medadimborder"}) 
      table_body = table.find('tbody')
      rows = table_body.findAll('tr')
      for row in rows:
          cols = row.findAll('td')
          cols = [ele.text.strip() for ele in cols]
          print cols</code>
  </code></p>
  
  <p>[u'01/16', u'130.7915', u'122.4640', u'117.9807', u'112.2557', u'105.8017', u'100.5720', u'98.6']
  [u'12/15', u'131.4547', u'123.0850', u'118.5790', u'112.8249', u'106.3383', u'101.0820', u'99.1']
  [u'11/15', u'131.5874', u'123.2092', u'118.6986', u'112.9387', u'106.4456', u'101.1840', u'99.2']</p>