-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataoutput.py
37 lines (34 loc) · 1.11 KB
/
Dataoutput.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
37
#coding: utf-8
import codecs
import csv
class DataOutput(object):
def __init__(self):
self.datas=[]
def store_data(self, data):
if data is None:
return
self.datas.append(data)
# def output_html(self):
# fout = codecs.open('wiki.html','w',encoding='utf-8')
# fout.write("<html>")
# fout.write("<head><meta charset='utf-8'/></head>'")
# fout.write("<body>")
# fout.write("<table>")
# for data in self.datas:
# fout.write("<tr>")
# fout.write("<td>%r</td>"%data['url'])
# fout.write("<td>%s</td>"%data['title'])
# fout.write("<td>%s</td>"%data['summary'])
# fout.write("</tr>")
# self.datas.remove(data) #写完就删
# fout.write("</table>")
# fout.write("</body>")
# fout.write("</html>")
# fout.close()
def output_csv(self):
headers = ['url', 'title', 'summary']
with open('wiki.csv', 'w') as f:
f_csv = csv.writer(f)
f_csv.writerow(headers)
f_csv.writerow(self.datas)
del self.datas