请教为什么出现没有属性'has_new_urls'
# coding:utf8
class UrlManager(object):#需要两个列表,待爬取的url和已经爬取过得url
def __init__(self):
self.new_urls = set()
self.old_urls = set()
def add_new_url(self,url):#向管理器中添加新的url
if url is None:
return
if url not in self.new_urls and url not in self.old_urls:#如果这个url既不在待爬取中也不在爬取过的
self.new_urls.add(url) #将其添加在待爬取中
def add_new_urls(self,urls):#向管理器中添加批量的url
if urls is None or len(urls) == 0:
return
for url in urls:
self.add_new_url(url)
def has_new_url(self):#判断管理器中是否有新的待爬取的url
return len(self.new_urls) != 0
def get_new_url(self):#获取新的待爬取的url
new_url = self.new_urls.pop()
self.old_urls.add(new_url)
return new_url