python的html.parser问题
python新手,用的是python3.1 怎么都执行不了,在命令行下逐行输入是可以的.报错误是:
Traceback (most recent call last):
File "D:\html.py", line 1, in <module>
from html.parser import HTMLParser
File "D:\html.py", line 1, in <module>
from html.parser import HTMLParser
ImportError: No module named parser
源代码是手册上的例子:
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
def handle_starttag(self,tag,attrs):
print("Encountered a {} start tag".format(tag))
def handle_endtag(self,tag):
print("Encountered a {} end tag".format(tag))
page = """<html><h1>Title</h1><p>I'm a paragraph!</p></html>"""
myparser = MyHTMLParser()
myparser.feed(page)