title: python - How to parse an HTML table
body: <p>I have a HTML page with about 50 tables on it. Each table has the same layout, but with different values, eg:</p>
  
  <pre><code>&lt;table align="right" class="customTableClass"&gt;
  &lt;tr align="center"&gt;
  &lt;td width="25" height="25" class="usernum"&gt;value1&lt;/td&gt;
  &lt;td width="25" height="25" class="usernum"&gt;value2&lt;/td&gt;
  &lt;td width="25" height="25" class="usernum"&gt;value3&lt;/td&gt;
  &lt;td width="25" height="25" class="usernum"&gt;value4&lt;/td&gt;
  &lt;td width="25" height="25" class="usernum"&gt;value5&lt;/td&gt;
  &lt;td width="25" height="25" class="usernum"&gt;value6&lt;/td&gt;
  &lt;td width="25" height="25" class="totalnum"&gt;otherVal&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>My <strong>REST server</strong> is running <strong>django/python</strong> so in my <code>urls.py</code> I am calling my <code>def parse_url():</code> function which obviously I want to do all the work in. My problem is, I'm pretty much a newbie when it comes to python, so literally just don't know where to put my code. I have gotten some code from the <code>HTMLParser</code> python docs, and changed it as follows:</p>
  
  <pre><code>import urllib, urllib2
  from django.http import HttpResponse
  from HTMLParser import HTMLParser
  
      class MyHTMLParser(HTMLParser):
          def handle_starttag(self, tag, attrs):
              print "Encountered the beginning of a %s tag" % tag
  
          def handle_endtag(self, tag):
              print "Encountered the end of a %s tag" % tag
  
          def handle_data(self, data):
              HttpResponse("Encountered data %s" % data)
  
  
      def parse_url(request):
          p = MyHTMLParser()
          url = 'http://www.mysite.com/lists.asp'
          content = urllib.urlopen(url).read()
          p.feed(content)
          return HttpResponse('DONE')
  </code></pre>
  
  <p>This code, at the moment, doesnt output anything useful. It just prints out <code>DONE</code>, which isnt very useful.</p>
  
  <p>How do I use the class methods such as <code>handle_starttag()</code>? Shouldnt these be called automatically when I use <code>p.feed(content)</code>??</p>
  
  <p>Basically, what I'm trying to accomplish in the end is, when I go to <code>mysite.com/showlist</code>, to be able to output a list saying:</p>
  
  <pre><code>value1
  value2
  value3
  value4
  value5
  value6
  
  othervalue
  </code></pre>
  
  <p>This needs to be done in a loop, because there is roughly 50 tables with different values in each table.</p>
  
  <p>Thanks for helping a beginner!!</p>