I want to inherit from Beautifulsoup Class to do the following tasks
<p>I am running on Python 3.5.1 with Beautifulsoup4.</p>

<p>I currently have this code: </p>

<pre><code>from bs4 import BeautifulSoup
import html5lib

class LinkFinder(BeautifulSoup):

  def __init__(self):
    super().__init__()

  def handle_starttag(self, name, attrs):
    print(name)
</code></pre>

<p>When I instantiate the class by the following code:
<code>findmylink = LinkFinder()</code> and when I load my html with the following code <code>findmylink.feed("""&lt;html&gt;&lt;head&gt;&lt;title&gt;my name is good&lt;/title&gt;&lt;/head&gt;&lt;body&gt;hello world&lt;/body&gt;&lt;/html&gt;""",'html5lib')</code>.</p>

<p>I got the following error in my console:</p>

<pre><code>'NoneType' object is not callable
</code></pre>

<p>I actually wish to duplicate the following sample code (in my case, I wishes to use Beautifulsoup instead of <code>html.parser</code>)</p>

<pre><code>from html.parser import HTMLParser
class LinkFinder(HTMLParser):

    def __init__(self):
        super().__init__()

   def handle_starttag(self, tag, attrs):
        print(tag)
</code></pre>

<p>When I re-instantiate the class by the following code: <code>findmylink = LinkFinder()</code> and when I load my html with the following code <code>findmylink.feed("""&lt;html&gt;&lt;head&gt;&lt;title&gt;my name is good&lt;/title&gt;&lt;/head&gt;&lt;body&gt;hello world&lt;/body&gt;&lt;/html&gt;""")</code> I get the following output:</p>

<pre><code>html
head
title
body
</code></pre>

<p>which is the desired output.</p>

<p>Not sure why do you need to use <code>BeautifulSoup</code> in such an uncommon way. If you want to simply get the names of all the elements in the HTML tree recursively:</p>

<pre><code>from bs4 import BeautifulSoup

data = """&lt;html&gt;&lt;head&gt;&lt;title&gt;my name is good&lt;/title&gt;&lt;/head&gt;&lt;body&gt;hello world&lt;/body&gt;&lt;/html&gt;"""

soup = BeautifulSoup(data, "html5lib")
for elm in soup.find_all():
    print(elm.name)
</code></pre>

<p>Prints:</p>

<pre><code>html
head
title
body
</code></pre>

python html python-3.x web-scraping beautifulsoup