NameError: name 'url_manager' is not defined
报错NameError: name 'url_manager' is not defined
class SpiderMain(object):
def __init__(self):
self.urls = url_manager.UrlManager()
self.downloader = html_downloader.HtmlDownloader()
self.parser = html_parser.HtmlParser()
self.output = html_outputer.HtmlOutputer()
def craw(self, root_url):
self.urls.add_new_url(root_url)
while self.urls.has_new_url():
new_url = self.urls.get_new_url()
print("第",count, '条: ', new_url)
html_cont = self.downloader.download()
new_urls, new_data = self.parser.parse(new_url, html_cont)
self.urls.add_new_urls(new_urls)
self.output.collect_data(new_data)
if count == 1000:
break
count += 1
self.output.output_html()
root_url="https://baike.baidu.com/item/Python/407313"
obj_spider = SpiderMain()
obj_spider.craw(root_url)