第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

anaconda python2 編碼問題

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>')
???????
??????? # ascii
??????? for data in self.datas:
??????????? fout.write('<tr>')
??????????? fout.write('<td>%s</td>' %data['url'].encode('utf-8'))
??????????? 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()

在爬蟲課程里,這個輸出器,無論我加了encode或者decode,都會出現(xiàn)ascii編碼錯誤,我用的是anaconda中的spyder python2.7 編譯的,也在網(wǎng)上找了很多方法,包括那個reload(sys) 都不行,你們有誰能解決這個問題嗎

正在回答

1 回答

#?Python?3.7?example
class?HtmlOutput(object):
????def?__init__(self):
????????self.store?=?[]
????def?save(self,?data):
????????if?data?is?None:
????????????return
????????#?data:?{url,?title,?summary}
????????self.store.append(data)
????def?output(self):
????????document?=?open('./output.html',?'w')
????????document.write('<html>')
????????document.write('<head><meta?charset=utf-8><title>Spider?Baike</title></head>')
????????document.write('<style>a{color:?#000;?text-decoration:?none}</style>')
????????document.write('<body>')
????????for?data?in?self.store:
????????????document.write('<h1><a?href="%s">%s</a></h1>'?%?(data['url'],?data['title']))
????????document.write('<p>%s</p>'?%?data['summary'])
????????document.write('</body>')
????????document.write('</html>')
????????document.close()
????????print?('Spider?is?over,?look?at?output.html')


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

舉報

0/150
提交
取消
Python開發(fā)簡單爬蟲
  • 參與學習       227603    人
  • 解答問題       1284    個

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

進入課程

anaconda python2 編碼問題

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號