亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

module 'url_manager' has no attribute 'UrlManager'

#這是我的主代碼,

#coding:utf-8
import url_manager,html_downloader,html_parser,html_outputer

class SpiderMain(object):
?? ?def __init__(self):
?? ??? ?# 在構造函數中進行初始化各個對象
?? ??? ?self.urls=url_manager.UrlManager()#url的管理器
?? ??? ?self.downloader=html_downloader.HtmlDownloader()#下載器
?? ??? ?self.parser=html_parser.HtmlParser()#解析器
?? ??? ?self.outputer=html_outputer.HtmlOutputer()#輸出器
?? ?# 爬蟲的調度程序
?? ?def craw(self,root_url):
?? ??? ?count = 1
?? ??? ?self.urls.add_new_url(root_url)
?? ??? ?while self.urls.has_new_url():
?? ??? ??? ?try:
?? ??? ??? ??? ?new_url = self.urls.get_new_url()
?? ??? ??? ??? ?print('craw %d:%s'%(count,new_url))
?? ??? ??? ??? ?html_cont = self.downloader.download(new_url)
?? ??? ??? ??? ?new_urls,new_data=self.parser.parse(new_url,html_cont)
?? ??? ??? ??? ?self.urls.add_new_urls(new_urls)
?? ??? ??? ??? ?self.outputer.collect_data(new_data)

?? ??? ??? ??? ?if count==1000:
?? ??? ??? ??? ??? ?break
?? ??? ??? ??? ?count = count+1
?? ??? ??? ?except:
?? ??? ??? ??? ?print('craw failed')

?? ??? ?self.outputer.output_html()?? ?

if __name__=="__main__":
?? ?root_url = "https://baike.baidu.com/item/python/407313"
?? ?obj_spider = SpiderMain()
?? ?obj_spider.craw(root_url)


class UrlManager(object):
??? """docstring for UrlManager"""
??? def __init__ (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)==0:
??????????? return
??????? for url in urls:
??????????? self.add_new_url(url)

??? def has_new_url(self):
??????? return len(self.new_urls) != 0

??? def get_new_url(self):
??????? new_url = self.new_urls.pop()
??????? self.old_urls.add(new_url)
?? ??? ?return new_url


這是url_manager.py的代碼,為什么先顯示沒有UrlManager的屬性呢?很迷惑,找了一天的bug了都沒找到,

正在回答

舉報

0/150
提交
取消
Python開發簡單爬蟲
  • 參與學習       227596    人
  • 解答問題       1288    個

本教程帶您解開python爬蟲這門神奇技術的面紗

進入課程

module 'url_manager' has no attribute 'UrlManager'

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號