码迷,mamicode.com
首页 > Web开发 > 详细

爬虫4 html输出器 html_outputer.py

时间:2016-11-30 03:17:17      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:data   htm   table   self   int   put   for   ini   sel   

#coding:utf8
__author__ = wang


class HtmlOutputer(object):

    def __init__(self):
        self.datas = [];

    def collect_data(self, data):
        if data is None:
            return
        print data
        self.datas.append(data)

    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>)

    def test(self):
        pass

 

爬虫4 html输出器 html_outputer.py

标签:data   htm   table   self   int   put   for   ini   sel   

原文地址:http://www.cnblogs.com/php-linux/p/6115808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!