首页 > IT职业 > > 不知道我哪里未定义new_urls
Traceback (most recent call last):
File "H:\python\qthnluwei\src\baike\spider_main.py", line 33, in <module>
obj_Spider.craw(root_url)
File "H:\python\qthnluwei\src\baike\spider_main.py", line 13, in craw
self.urls.add_new_url (root_url)
File "H:\python\qthnluwei\src\baike\url_manager.py", line 11, 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'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | class UrlManager(object): def __int__(self): self.new_urls = set() self.old_urls = set() def add_new_url(self,url): if url is None: return if url not in self.new_urls and url not in self.old_urls: self.new_urls.add(url) def add_new_urls(self,urls): if urls is None or len(urls) == : return for url in urls: self.add_new_url(url) def has_new_url(self): return len(self.new_urls) != def get_new_url(self): new_url = self.new_urls.pop() self.old_urls.add(new_url) return new_url |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1812/viewspace-3158899/ ,如需转载,请注明出处,否则将追究法律责任。