爬虫4 html输出器 html_outputer.py

原文链接: http://www.cnblogs.com/php-linux/p/6115808.html
#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('')
        fout.write('')
        fout.write('')

        for data in self.datas:
            fout.write('')
            fout.write('' % data['url'])
            fout.write('' % data['title'].encode('utf-8'))
            fout.write('' % data['summary'].encode('utf-8'))
            fout.write('')

        fout.write('
%s%s%s
') fout.write('') fout.write('') def test(self): pass

 

转载于:https://www.cnblogs.com/php-linux/p/6115808.html

你可能感兴趣的:(爬虫4 html输出器 html_outputer.py)