title: How to loop through a html-table-dataset in Python
body: <p>I'm first time poster here trying to pick up some Python skills; please be kind to me :-)</p>
  
  <p>While I'm not a complete stranger to programming concepts (I've been messing around with PHP before), the transition to Python has turned out to be somewhat difficult for me. I guess this mostly has to do with the fact that I lack most - if not all - basic understanding of common "design patterns" (?) and such.</p>
  
  <p>Having that said, this is the problem. Part of my current project involves writing a simple scraper by utilizing Beautiful Soup. The data to be processed has a somewhat similar structure to the one which is laid out below.</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;td class="date"&gt;2011-01-01&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="item"&gt;
          &lt;td class="headline"&gt;Headline&lt;/td&gt;
          &lt;td class="link"&gt;&lt;a href="#"&gt;Link&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="item"&gt;
          &lt;td class="headline"&gt;Headline&lt;/td&gt;
          &lt;td class="link"&gt;&lt;a href="#"&gt;Link&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td class="date"&gt;2011-01-02&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="item"&gt;
          &lt;td class="headline"&gt;Headline&lt;/td&gt;
          &lt;td class="link"&gt;&lt;a href="#"&gt;Link&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="item"&gt;
          &lt;td class="headline"&gt;Headline&lt;/td&gt;
          &lt;td class="link"&gt;&lt;a href="#"&gt;Link&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>The main issue is that I simply can't get my head around how to 1) keep track of the current date (tr->td class="date") while 2) looping over the items in the subsequent tr:s (tr class="item"->td class="headline" and tr class="item"->td class="link") and 3) store the processed data in an array.</p>
  
  <p>Additionally, all data will be inserted into a database where each entry must contain the following information;</p>
  
  <ul>
  <li>date</li>
  <li>headline</li>
  <li>link</li>
  </ul>
  
  <p><em>Note that crud:ing the database is not part of the problem, I only mentioned this in order to better illustrate what I'm trying to accomplish here :-)</em></p>
  
  <p>Now, there are many different ways to skin a cat. So while a solution to the issue at hand is indeed very welcome, I'd be extremely grateful if someone would care to elaborate on the actual logic and strategy you would make use of in order to "attack" this kind of problem :-)</p>
  
  <p>Last but not least, sorry for such a noobish question.</p>