class MyHTMLParser(HTMLParser):
b1 = False
def handle_starttag(self, tag, attrs):
if tag =="ul":
self.b1 = True
def handle_data(self, data):
if self.b1:
print(data)
self.b1 = False
parser = MyHTMLParser()
parser.feed('<ul class="player-metadata floatleft"></ul><p>Gros caca</p><p>Zuul</p>')
I want to extract the data between <ul class="player-metadata floatleft"> and </ul> which is empty. However, even though I flagged the <ul> tag, the handle_data function prints the first data found after <ul class="player-metadata floatleft"></ul>:
"Gros caca"
I would like to print "nothing" and that len(data) returns 0.
Could you please help me? I am also not allowed to use BeautifulSoup.