title: Python: Get data between html tags if an attribute matches and put it into a list
body: <p>this is part of a html file.</p>
  
  <pre><code>......
  ......
  &lt;tr&gt;
  &lt;td color="white" style="color:black; bgcolor="#ffff00"&gt;Adam&lt;/th&gt;
  &lt;td color="white" style="color:white; bgcolor="#ff9900"&gt;450231&lt;/th&gt;
  &lt;td color="white" style="color:black; bgcolor="#cc0000"&gt;658902&lt;/th&gt;
  &lt;/tr&gt;
  .......
  .......
  &lt;tr&gt;
  &lt;td color="white" style="color:black; bgcolor="#ffff00"&gt;John&lt;/th&gt;
  &lt;td color="white" style="color:white; bgcolor="#ff9900"&gt;8734658&lt;/th&gt;
  &lt;td color="white" style="color:black; bgcolor="#cc0000"&gt;90865&lt;/th&gt;
  &lt;/tr&gt;
  .......
  .......
  </code></pre>
  
  <p>if <code>bgcolor="#ff9900"</code>, I need to extract 450231 and 8734658 and put them into a list</p>
  
  <p>So far, I've done this..</p>
  
  <pre><code>class MyHTMLParser(HTMLParser):
      def __init__(self):
          HTMLParser.__init__(self)
          self.recording = 0
          self.data = []
  
      def handle_starttag(self, tag, attrs):
          if tag == 'td':
              for name, value in attrs:
                  if name == 'bgcolor' and value == '#993399':
                      self.recording = 1 
  
      def handle_endtag(self,tag):
          if tag == 'th':
              self.recording -= 1
  
      def handle_data(self, data):
          if self.recording:
              self.data.append(data)
  .
  .
  .
          y = urllib2.urlopen(x)   # x gets the html file
          html = y.read()
          parser = MyHTMLParser()
          parser.feed(html)
          print parser.data
          parser.close()
  </code></pre>
  
  <p>parser.data contains <code>['\n', 'Adam', '\n', '450231', '\n', '658902\n', '\n', '\n', '\n'....]</code> when it should contain only <code>['450231', '8734658']</code> I'm not sure where I'm going wrong.</p>