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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python爬蟲爬了2個就報錯

python爬蟲爬了2個就報錯

小寶君等期待 2016-08-19 11:20:18
報錯信息:craw 1:http://baike.baidu.com/view/21087.htmcraw failedTraceback (most recent call last):? File "E:\python\python_practice1\baidubaike\spider_main.py", line 39, in <module>? ? obj_spider.craw(root_url)?? File "E:\python\python_practice1\baidubaike\spider_main.py", line 34, in craw? ? self.outputer.output_html()TypeError: output_html() missing 1 required positional argument: 'self'貼上html_outputer代碼:class HtmlOutputer(object):? ?def __init__(self):? ? ? ?self.datas = []? ? ? ?? ?def collect_data(self,data):? ? ? ?if data is None:? ? ? ? ? ?return? ? ? ?self.datas.append(data)? ? ??? ?def output_html(self):? ? ? ?fout = open('output.html','w')? ? ? ?? ? ? ?fout.write('<html>')? ? ? ?fout.write('<body>')? ? ? ?fout.write('<table>')? ? ? ?for data in self.datas:? ? ? ? ? ?fout.write('<tr>')? ? ? ? ? ?fout.write('<td>%s</td>'% data['url'])? ? ? ? ? ?fout.write('<td>%s</td>'% data['title'].encode('utf-8'))? ? ? ? ? ?fout.write('<td>%s</td>'% data['summary'].encode('utf-8'))? ? ? ? ? ?fout.write('</tr>')? ? ? ?fout.write('</table>')? ? ? ?fout.write('</body>')? ? ? ?fout.write('</html>')? ? ? ?fout.close()
查看完整描述

2 回答

?
慕粉3843115

TA貢獻1條經驗 獲得超0個贊

從報錯上看,是缺少一個參數self。

你應該是沒有實例化HtmlOutputer這個類

需要用outputer =?HtmlOutputer()

outputer.collect_data()

而不是用outputer =?HtmlOutputer

outputer.collect_data()


估計上一個問的問題應該也是同樣的原因哈

查看完整回答
反對 回復 2016-08-24
  • 2 回答
  • 0 關注
  • 2132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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