crawl.py。我尝试将其移植到python3。我遗漏了所有不必要的细节。 错误:
Traceback (most recent call last):
File "crawl.py", line 44, in parseAndGetLinks
self.parser = html.parser(AbstractFormatter(DumbWriter(StringIO())))
TypeError: 'module' object is not callable
import html.parser
from formatter import DumbWriter, AbstractFormatter
from io import StringIO
parser = html.parser(AbstractFormatter(DumbWriter(StringIO())))
答案 0 :(得分:5)
html.parser
是模块;你想要那个模块中的HTMLParser
class :
parser = html.parser.HTMLParser(AbstractFormatter(DumbWriter(StringIO())))
或更简洁:
from html.parser import HTMLParser
parser = HTMLParser(AbstractFormatter(DumbWriter(StringIO())))