报错信息: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()
估计上一个问的问题应该也是同样的原因哈
添加回答
举报
0/150
提交
取消