如何将爬虫内容写入TXT,f.write()问题

来源:互联网 发布:灰色系统建模软件 编辑:程序博客网 时间:2024/05/18 03:53
# -*- coding:UTF-8 -*-test = u"编码问题"test = test.encode('utf-8')with open('1.txt',"a+") as f:    f.write(test)    f.close
但爬虫内容为列表,所以改进为:
# coding:UTF-8a =[u"编码问题1",u"编码问题2",u"编码问题3"]with open("1.txt","w") as f:    for i in a:        test2 = i.encode('UTF-8')        f.write(test2)    f.close    



原创粉丝点击