title: Parsing <span> tag and getting data with python
body: <p>I'm new on stackoverflow and this is my first question.</p>
  
  <p>I'm writing script in Python for parsing HTML page.
  Page looks like this:</p>
  
  <pre><code>&lt;TABLE style="border: 1px solid black"&gt;
  
  &lt;TR&gt;
      &lt;TD colspan="2"&gt;&lt;span id="text1" style="color: white"&gt;DATA1&lt;/span&gt;&lt;/TD&gt;
  &lt;/TR&gt;
  &lt;TR&gt;    
      &lt;TD class="rowLabel" valign="top"&gt;Data name&lt;/TD&gt;
      &lt;TD valign="top" width="100"&gt;&lt;span id="somename1" class="alsoname"&gt;DATA2&lt;/span&gt;&lt;/TD&gt;
  &lt;/TR&gt;   
  &lt;TR&gt;    
      &lt;TD class="rowLabel" valign="top"&gt;Data name&lt;/TD&gt;
      &lt;TD valign="top" width="100"&gt;&lt;span id="somename2" class="alsoname"&gt;DATA3&lt;/span&gt;&lt;/TD&gt;
  &lt;/TR&gt;                                               
  &lt;TR&gt;
      &lt;TD class="rowLabel" valign="top"&gt;Data name&lt;/TD&gt;
      &lt;TD valign="top" width="100"&gt;&lt;span id="somename3" class="alsoname"&gt;DATA4&lt;/span&gt;&lt;/TD&gt;
  &lt;/TR&gt;
  &lt;TR&gt;
      &lt;TD class="rowLabel" valign="top"&gt;Data name&lt;/TD&gt;
      &lt;TD valign="top" width="100"&gt;&lt;span id="somename4" class="alsoname"&gt;DATA5&lt;/span&gt;&lt;/TD&gt;
  &lt;/TR&gt;
  &lt;TR&gt;
      &lt;TD class="rowLabel" valign="top"&gt;Data name&lt;/TD&gt;
      &lt;TD valign="top" width="100"&gt;&lt;span id="somename5" class="alsoname"&gt;DATA6&lt;/span&gt;&lt;/TD&gt;
  &lt;/TR&gt;                                               
  &lt;TR&gt;
      &lt;TD class="rowLabel" valign="top"&gt;Data name&lt;/TD&gt;
      &lt;TD valign="top" width="100"&gt;&lt;span id="somename6" class="alsoname"&gt;DATA7&lt;/span&gt;&lt;/TD&gt;
  &lt;/TR&gt;
  &lt;TR&gt;
      &lt;TD class="rowLabel" valign="top"&gt;Data name&lt;/TD&gt;
      &lt;TD valign="top" width="100"&gt;&lt;span id="somename7" class="alsoname"&gt;DATA8&lt;/span&gt;&lt;/TD&gt;
  &lt;/TR&gt;                           
  </code></pre>
  
  <p></p>
  
  <p>I would like to collect DATA values from  brackets based on span id name.
  If span ID == somename1 then put it's DATA value in variable.</p>
  
  <p>so far I have this code:</p>
  
  <pre><code>from HTMLParser import HTMLParser
  
  class MyHTMLParser(HTMLParser):
      def handle_starttag(self, tag, attrs):
          if tag == 'span':
              for name, value in attrs:
                  if name == 'id' and value == 'somename1':
                      print 'ID', value
                  elif name == 'id' and value == 'somename2':
                      print 'ID', value
                  elif name == 'id' and value == 'somename3':
                      print 'ID', value
                  else :
                      print 'NO DATA'
  
  p = MyHTMLParser()
  p.feed(flush)  
  </code></pre>
  
  <p>Can anybody help me?</p>