【发布时间】:2013-05-02 02:40:54
【问题描述】:
我有以下解析器:
class Parser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.tableCount = 0
def handle_starttag(self, tag, attrs):
if tag == "table":
for attr in attrs:
if attr[0] == "class" and attr[1] == "space":
## need to do some processing here
代替 cmets,我需要做的是在此点之后步进所有 HTML 实体,直到 table 标记结束(此代码仅在 tag == table 时运行,如上所示。
我该怎么做?我看不到任何方法可以逐步浏览此标签下的所有标签。请注意,我不能使用任何外部库,例如 BeautifulSoup(只是 Python 标准库)。
【问题讨论】:
标签: python html-parsing python-3.3