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(r'D:\baidu download\java\output.html', 'w')? ? ? ? fout.write("<html>") ? ? ? ?? ? ? ? fout.write("<body>")? ? ? ? fout.write("<table>")? ? ? ? for data in self.datas:? ? ? ? ? ? #fout.write('<meta charset="utf-8">')? ? ? ? ? ? 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("</table>")? ? ? ? fout.write("</body>")? ? ? ? fout.write("</html>")
控制臺運行結果正確,但是輸出的output.html文件只有第一個python百科網址,其他的顯示不出來。
慕粉1914306576
2018-01-15 21:35:17