json转化为csv文件打开时,中文乱码
三种方法:
-
法一
用笔记本打开csv文件,在笔记本中选择“文件”-->“另存为”。设置编码类型为‘utf-8\'
- 法二
在打开的excel页面中,选择“文件”菜单-->选项-->语言设置为简体中文
- 法三
1.数据-->从文本
2.依此设置。文件格式设置为 “无(常规)”
附json->csv代码:
import csv import json with open(\'\'\'d:/python/爬虫/txt文件/豆瓣电影top_250.txt\'\'\',\'r\',encoding=\'utf-8\') as f: fieldnames=\'\'\'[\'index\',\'name\',\'DaA\',\'score\',\'quote\']\'\'\' items=f.readlines() content=[] for item in items: content.append(\'\'\'eval(item.strip())\'\'\') with open(\'\'\'d:/python/爬虫/txt文件/豆瓣电影top_250.csv\'\'\',\'a\',encoding=\'utf-8\',newline=\'\') as ff: writer=csv.DictWriter(ff,fieldnames=fieldnames) writer.writeheader() writer.writerows(content)