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) 都不行,你們有誰能解決這個問題嗎
2019-02-08