函數(shù)的調(diào)用報錯obj_spider.craw(root_url)和def craw(self, root_url)
Traceback (most recent call last):
? File "/Users/Bruce/GitHub/python/baike_spider/spider_main.py", line 38, in <module>
? ? obj_spider.craw(root_url)
? File "/Users/Bruce/GitHub/python/baike_spider/spider_main.py", line 16, in craw
? ? self.urls.add_new_url(root_url)
? File "/Users/Bruce/GitHub/python/baike_spider/url_manager.py", line 12, in add_new_url
? ? if url not in self.new_urls and url not in self.old_urls:
AttributeError: 'UrlManager' object has no attribute 'new_urls'
2016-05-24
需要定義構造函數(shù)與,在構造函數(shù)中對new_urls進行初始化,構造函數(shù)代碼如下
def __init__(self):
? ? ? ? self.new_urls = set()
? ? ? ? self.old_urls = set()
2016-05-24
new_urls是不是沒有初始化?