使用utf-8还是乱码
output
def output_html(self):
fout=open('output.html','w')
fout.write("<html>")
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'))
# fout.write("<td>$s</td>"%data['summary'].encode("utf-8"))
fout.write("</tr>")
fout.write("</table>")
fout.write("</body>")
fout.write("</html>")
fout.close()
输出结果
<html><body><table<tr><td>b'Python'</td><td>$s</td></tr><tr><td>b'MySQLdb'</td><td>$s</td></tr><tr><td>b'\xe8\xae\xa1\xe7\xae\x97\xe6\x9c\xba\xe7\xa8\x8b\xe5\xba\x8f\xe8\xae\xbe\xe8\xae\xa1\xe8\xaf\xad\xe8\xa8\x80'</td><td>$s</td></tr><tr><td>b'PyGTK'</td><td>$s</td></tr><tr><td>b'HTML'</td><td>$s</td></tr><tr><td>b'\xe6\xba\x90\xe6\x96\x87\xe4\xbb\xb6'</td><td>$s</td></tr><tr><td>b'\xe6\xad\xa3\xe6\x96\x87'</td><td>$s</td></tr><tr><td>b'M-net'</td><td>$s</td></tr><tr><td>b'Haskell'</td><td>$s</td></tr></table></body></html>