输出问题是b'\xe6\x96\x87\xe6\x9c\xac\xe7\xbc\x96\xe8\xbe\x91\xe5\x
我的输出全部都是类似这样的b'\xe6\x96\x87\xe6\x9c\xac\xe7\xbc\x96\xe8\xbe\x91\xe5\x
怎样才能输出下常的东西呢?
我的输出全部都是类似这样的b'\xe6\x96\x87\xe6\x9c\xac\xe7\xbc\x96\xe8\xbe\x91\xe5\x
怎样才能输出下常的东西呢?
2016-09-02
def output_html(self):
fout=open('output.html','w',encoding='utf-8')
fout.write('<html>')
fout.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />')
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').decode('utf-8'))
fout.write('<td>%s</td>' % data['summary'].encode('utf-8').decode('utf-8'))
fout.write('</tr>')
fout.write('</table>')
fout.write('</body>')
fout.write('</html>')
自己已经解决,也是参考了别的问题上的答案,
方法一:
fout.write("<html><meta charset=\"utf-8\" />")
下面这些不需要再写encode('utf-8')
fout.write('<td>%s</td>'%data['url'])
fout.write('<td>%s</td>'%data['title'])
fout.write('<td>%s</td>'%data['summary'])
方法二:
fout.write("<html>")
下面这些需要再写encode('utf-8')和decode
fout.write('<td>%s</td>'%data['url'].encode('utf-8').decode('utf-8'))
fout.write('<td>%s</td>'%data['title'].encode('utf-8').decode('utf-8'))
fout.write('<td>%s</td>'%data['summary'].encode('utf-8').decode('utf-8'))
原因不懂,但解决了问题
举报