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>If you want to go this way, change your implementation to accept the markup during initialization and <a href="https://github.com/JinnLynn/beautifulsoup/blob/f29f8d278462efb370168f2329b070fa51706013/bs4/__init__.py#L310" rel="nofollow"><code>handle_starttag</code></a> to grab all passed args:</p>

<pre><code>class LinkFinder(BeautifulSoup):

  def __init__(self, markup):
    super().__init__(markup, 'html.parser')

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

<p>Initializing with:</p>

<pre><code>l = LinkFinder("""&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></pre>

<p>Prints out:</p>

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

<p>I'm pretty sure the <code>BeautifulSoup</code> class has overloaded <code>__getattr__</code> to return <code>None</code> on non-defined attributes instead of raising <code>AttributeError</code>; that's what's causing your error:</p>

<pre><code>print(type(BeautifulSoup().feed))
NoneType
print(type(BeautifulSoup().feedededed))
NoneType
</code></pre>

<p>and, <code>BeautifulSoup</code> doesn't have a <code>feed</code> function as <code>HTMLParser</code> does (it does have a <a href="https://github.com/JinnLynn/beautifulsoup/blob/f29f8d278462efb370168f2329b070fa51706013/bs4/__init__.py#L193" rel="nofollow"><code>_feed</code></a> and that calls the underlying <code>feed</code> of the <code>builder</code> object with <code>self.markup</code>) so you get a <code>None</code> object which you call.</p>

python html python-3.x web-scraping beautifulsoup