Skip to content Skip to sidebar Skip to footer

Subclassing Beautifulsoup Html Parser, Getting Type Error

I wrote a little wrapper using beautifulsoup great html parser recently I tried to improve the code and make all beautifulsoup methods available directly in the wrapper class (inst

Solution 1:

The error is not happening in BeautifulSoup code. Rather, your IDLE is not able to retreive and print the object. Try print str(e) instead.


Anyway, subclassing BeautifulSoup in your situation may not be the best idea. Do you really want to inherit all of the parsing methods (like convert_charref, handle_pi or error)? Worse, if you override something that BeautifulSoup uses, it may break in a hard-to-find way.

I don't know your situation, but I suggest preferring composition over inheritance (i.e. having a BeautifulSoup object in an attribute). You can easily (if in a slightly hacky way) expose specific methods like this:

classScrape(object):def__init__(self, ...):
        self.soup = ...
        ...
        self.find = self.soup.find

Post a Comment for "Subclassing Beautifulsoup Html Parser, Getting Type Error"