title: Python : looping through each row of html table based on headers
body: <p>I'm new to python(3.4) and have parsed an html table into headings[ ] , rows[ ] and cells [ ]
  I wish to store each of these into a table (MySQL) eventually with the field names being the items in the headings[ ]</p>
  
  <p>There are 4 headings("data0","data1","data2","data3")
  There are 6 rows</p>
  
  <p>The code to get there is very rudimentary using BeautifulSoup:</p>
  
  <pre><code>soup = BeautifulSoup(r.text)
  table = soup.find("table")
  cells = []
  rows = table.findAll('tr')
  headings = [th.get_text().strip() for th in table.findAll("th")]
  for row in rows:
      for cell in row.findAll('td')
      cells .append(cell.get_text().strip())
  </code></pre>
  
  <p>I'm used to doing CASE statements, or, heaven forbid, a number of IF statements. I would normally place them under the 
  for cell in row.findAll('td')  . But I would be working with a counter and be doing something like:</p>
  
  <pre><code>for row = 0 to len(rows)
      for cell = 0 to len(headings)
           select case cell
      case = 0 
        (save cell contents to field called headings[0]
      case = 1
        (save cell contents to field called headings[1]       
  ...
  </code></pre>
  
  <p>I'm not too worried about the saving part (yet) but I cant wrap my head around not being able to use counters.
  I realize this is way beginner, but I should would appreciate any insight (and so would my brain)</p>