title: get contents of <a> tags using python
body: <p>Assuming I have html read into my program like this:</p>
  
  <pre><code>&lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/nvn/ret/1817849271.html"&gt;F/T &amp;amp; P/T Sales Associate - Caliente Fashions&lt;/a&gt; - &lt;font size="-1"&gt; (North Vancouver)&lt;/font&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/van/ret/1817804151.html"&gt;IMMEDIATE EMPLOYMENT WANTED!&lt;/a&gt; - &lt;/p&gt;
  
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/nvn/ret/1817796152.html"&gt;TRAVEL AGENT&lt;/a&gt; - &lt;font size="-1"&gt; (NORTH VANCOUVER)&lt;/font&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/bnc/ret/1817775400.html"&gt;Optical Sales Position&lt;/a&gt; - &lt;font size="-1"&gt; (New Westminster)&lt;/font&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/van/ret/1817709780.html"&gt;Sales Clerk&lt;/a&gt; - &lt;font size="-1"&gt; (Kits)&lt;/font&gt;&lt;/p&gt;
  
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/van/ret/1817676850.html"&gt;MARINE SALES&lt;/a&gt; - &lt;font size="-1"&gt; (VANCOUVER ( KITS ))&lt;/font&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/van/ret/1817608506.html"&gt;Retail Sales Associate&lt;/a&gt; - &lt;font size="-1"&gt; (Vancouver)&lt;/font&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/van/ret/1817573985.html"&gt;Retail with small parts appliance background&lt;/a&gt; - &lt;/p&gt;
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/rds/ret/1817540938.html"&gt;Manager *Enjoyable work atmosphere&lt;/a&gt; - &lt;font size="-1"&gt; (Langley Centre)&lt;/font&gt;&lt;/p&gt;
  
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/bnc/ret/1817403652.html"&gt;Team Member - Retail Store - FT&lt;/a&gt; - &lt;font size="-1"&gt; (Burnaby South)&lt;/font&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/rds/ret/1817459155.html"&gt;STORE MANAGER-SHOE WAREHOUSE&lt;/a&gt; - &lt;font size="-1"&gt; (South Surrey-Semiahmoo)&lt;/font&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href="http://vancouver.en.craigslist.ca/pml/ret/1817448777.html"&gt;Retail Sales&lt;/a&gt; - &lt;font size="-1"&gt; (Coquitlam)&lt;/font&gt;&lt;/p&gt;
  </code></pre>
  
  <p>How do I grab the contents of the text node? What I would like to end up with is printing something similar to this line in the terminal:</p>
  
  <pre><code>http://vancouver.en.craigslist.ca/nvn/ret/1817849271.html - TRAVEL AGENT
  </code></pre>
  
  <p>So far I have the following code which extracts the href link fine but I'm not sure how to extract the data itself. I'm thinking of overriding <code>handle_data(self, data)</code> from the sgmllib.py module but so far I can't seem to think of a way to do it.</p>
  
  <pre><code>from sgmllib import SGMLParser
  
  class URLLister(SGMLParser):
      def reset(self):
          SGMLParser.reset(self)
          self.urls = []
  
      def start_a(self, attrs):
          href = [v for k, v in attrs if k == "href"]
          if href:
              self.urls.extend(href)
  </code></pre>
  
  <p>Thanks!</p>