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

爬虫内容为列表,所以改进为:

1
2
3
4
5
6
7
8
# coding:UTF-8
a =[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

from:https://blog.csdn.net/a2437383438/article/details/78375738

发表评论

:?: :razz: :sad: :!: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: :smile: :evil:
贴图 表情 ( ps. 若要贴代码, 请將 "<" 改成 "&lt;" 即可. )

3 + 9 = ?

这篇文章上的评论的RSS feed TrackBack URL