我正在使用HTMLParser解析HTML文档,我想要打印出p标签开始和结束之间的内容。以下是我的代码片段:
def handle_starttag(self, tag, attrs):
if tag == 'p':
print "TODO: print the contents"
feed
方法了,而列表使用的方法是append
而非push
。 - tauranif self.tag_stack[-1] == 'p': IndexError: list index out of range
的错误。 - Matthieu Rieglertag_stack
是空的? - Daren Thomasif len(self.tag_stack) and self.tag_stack[-1] == 'p':
。 - Daren Thomas