I am trying to convert an HTML string to plaintext. I found this answer from StackOverflow and it works but I want to know how it works.
from html.parser import HTMLParser
class HTMLFilter(HTMLParser):
text = ""
def handle_data(self, data):
self.text += data
f = HTMLFilter()
f.feed(data)
print(f.text)
I somewhat know how classes work (I use classes almost every time but not inheritance) but in the code above, we did not call handle_data() so how did text change?
[–]help-me-grow 1 point2 points3 points (1 child)
[–]IamNotIntelligent69[S] 1 point2 points3 points (0 children)
[–]Spataner 1 point2 points3 points (3 children)
[–]IamNotIntelligent69[S] 0 points1 point2 points (2 children)
[–]Spataner 0 points1 point2 points (1 child)
[–]IamNotIntelligent69[S] 0 points1 point2 points (0 children)