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

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

我把html_output這個文件修改了下,就提示我AttributeError: 'HtmlOutputer' object has no attribute 'save_excel'

# -*-coding:UTF-8-*-
import xlsxwriter

class HtmlOutputer(object):
? ?def __init__(self): ?# 建立列表存放數據
? ? ? ?self.datas = []

? ?def collect_data(self,data): ?# 收集數據
? ? ? ?if data is None:
? ? ? ? ? ?return
? ? ? ?self.datas.append(data)

? ?def save_excel(self):
? ? ? ?book = xlsxwriter.Workbook(r'C:\Users\Administrator\Desktop\abc.xlsx') #默認儲存在桌面
? ? ? ?tmp = book.add_worksheet() #建立sheet
? ? ? ?row_num = 11 #行號
? ? ? ?for data in self.datas:
? ? ? ? ? ?for i in range(1, 11):
? ? ? ? ? ? ? ?tag_pos1 = 'A%s' % i
? ? ? ? ? ? ? ?tmp.write(tag_pos1,data['url'])
? ? ? ? ? ? ? ?tag_pos2 = 'B%s' % i
? ? ? ? ? ? ? ?tmp.write(tag_pos2,data['title'])
? ? ? ? ? ? ? ?tag_pos3 = 'C%s' % i
? ? ? ? ? ? ? ?tmp.write(tag_pos3,data['summary'])
? ? ? ?book.close()

代碼如上,我的類里明明已經定義了這個方法,求大佬指教,我用的是pycharm,第三方模塊已經全部導入了

正在回答

1 回答

你的save_excel是方法,先在你調用的類里面, 把HtmlOutputer這個對象生成了

self.outputer = html_outputer.HtmlOutputer()

然后 outputer.save_excel()?
注意excel加括號

0 回復 有任何疑惑可以回復我~
#1

金至則城 提問者

可能是以前編譯的pyc文件有望問題
2017-02-22 回復 有任何疑惑可以回復我~

舉報

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

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

進入課程

我把html_output這個文件修改了下,就提示我AttributeError: 'HtmlOutputer' object has no attribute 'save_excel'

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

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

幫助反饋 APP下載

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

公眾號

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