• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

python爬虫爬了2个就报错

报错信息:

craw 1:http://baike.baidu.com/view/21087.htm
craw failed
Traceback (most recent call last):
  File "E:\python\python_practice1\baidubaike\spider_main.py", line 39, in
    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('')
       fout.write('')
       fout.write('')
       for data in self.datas:
           fout.write('')
           fout.write('%s'% data['url'])
           fout.write('%s'% data['title'].encode('utf-8'))
           fout.write('%s'% data['summary'].encode('utf-8'))
           fout.write('')
       fout.write('')
       fout.write('')
       fout.write('')
       fout.close()

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

从报错上看,是缺少一个参数self。
你应该是没有实例化HtmlOutputer这个类
需要用outputer =HtmlOutputer()
outputer.collect_data()
而不是用outputer =HtmlOutputer
outputer.collect_data()


估计上一个问的问题应该也是同样的原因哈

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!