forked from AbelSu131/baike_spider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml_outputer.py
36 lines (28 loc) · 931 Bytes
/
html_outputer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding=utf-8
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("<head>")
fout.write("<meta charset= 'UTF-8'>")
fout.write("</head>")
fout.write("<body>")
fout.write("<table>")
# ASCII
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("</html>")
fout.write("</body>")
fout.write("</table>")
fout.close()