'Why do I need to override the handle_data method in my own class?
Why do I need to override the handle_data() method when it already exists in the library here: https://docs.python.org/3/library/html.parser.html#html.parser.HTMLParser
This answer explains that the default behaviour of handle_data() is nothing, but I don't understand how that can be: Python overidable functions from HTMLParser
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
# Why does this not work?
# test = HTMLParser.handle_data(self, data)
# print(test)
#Why do I need to define handle_data() when it already exists in the library?
def handle_data(self, data):
print(data)
URL = "https://en.wikipedia.org/wiki/Data_science"
text = requests.get(URL).content.decode('utf-8')
parser = MyHTMLParser()
parser.feed(text)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
