課程
/后端開發
/Python
/Python開發簡單爬蟲
name 'new_urls' is not defined
這個怎么解決
2016-12-01
源自:Python開發簡單爬蟲 7-5
正在回答
感覺你是最近才學的吧。如果是,建議你學習一下基礎,然后一個一個模塊的學習使用。最后再一次使用多個模塊。而且,這個視頻的python和模塊有點老,你要小心有很多坑,我就是被坑了很多次?。。?/p>
第20行中第一個new_urls
改了,只執行了2行
豬豬的笨笨
厲害咯 提問者 回復 豬豬的笨笨
豬豬的笨笨 回復 厲害咯 提問者
第一個new_url加上s就好了
厲害咯 提問者
第20行,new_url沒有s
#調度程序 import?url_manager,?html_downloader,?html_parser,?html_outputer class?SpiderMain(object): ????def?__init__(self): ????????self.urls?=?url_manager.UrlManager() ????????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_url,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?Exception?as?err: ????????????????print(err) ????????self.outputer.output_html() if?__name__?==?"__main__": ????root_url?=?"http://baike.baidu.com/view/21087.htm" ????obj_spider?=?SpiderMain() ????obj_spider.craw(root_url)
美女,是你的spider_main文件出問題了。貼出來spider_main文件
只執行了一個
報錯的東西截圖出來
我用的是python3.5
舉報
本教程帶您解開python爬蟲這門神奇技術的面紗
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-12-01
感覺你是最近才學的吧。如果是,建議你學習一下基礎,然后一個一個模塊的學習使用。最后再一次使用多個模塊。而且,這個視頻的python和模塊有點老,你要小心有很多坑,我就是被坑了很多次?。。?/p>
2016-12-01
2016-12-01
改了,只執行了2行
2016-12-01
第一個new_url加上s就好了
2016-12-01
第20行,new_url沒有s
2016-12-01
2016-12-01
美女,是你的spider_main文件出問題了。貼出來spider_main文件
2016-12-01
只執行了一個
2016-12-01
報錯的東西截圖出來
2016-12-01
我用的是python3.5