html_outputer.py
coding=UTF-8
# HTML输出器
import sys
class htmlOutputer():
def __init__(self):
self.data = []
def collect_data(self, data):
if data is None:
return
self.data.append(data)
def output(self):
global file
try:
file = open('output.html', 'w',encoding='utf-8')
file.write('<html>')
file.write('<body>')
file.write('<table>')
for data in self.data:
file.write('<tr>')
file.write('<td>%s</td>' % data['url'])
file.write('<td>%s</td>' % data['title'].encode('utf-8').decode('utf-8'))
file.write('<td>%s</td>' % data['summary'].encode('utf-8').decode('utf-8'))
file.write('</tr>')
file.write('</table>')
file.write('</body>')
file.write('</html>')
file.close()
except IOError as e:
print(str(e))
finally:
if 'file' in locals():
file.close()
岑忠满的博客新站点
http://cenzm.xyz