Open songku opened 2 years ago
import json import csv import sys import os print("usage:python Ehole_json2csv.py <json file path>") csv_headers = ['url', 'cms', 'server', 'statuscode', 'length', 'title'] json_path = sys.argv[1] # debug use 如果在终端使用,应该注释掉下面的内容,使用上面的 # json_path = "./sub_outcome.json" if os.path.exists(json_path): with open(json_path, encoding="utf-8") as json_file: json_datas = json_file.readlines() else: print(json_path, " did not exist,please check") exit(0) print("read json file ", json_path, " ok") home_path = json_path.split(".json")[0] # 从json文件路径提取出.json前面的路径 csv_path = home_path + ".csv" # csv的路径与json前面的路径一致 if os.path.exists(csv_path): print(csv_path, " has been generated,try to change your json file name or check this csv file") exit(0) csv_file = open(csv_path, 'w', encoding="utf-8-sig", newline="") csv_write = csv.writer(csv_file) csv_write.writerow(csv_headers) print("start write csv file...") for json_data in json_datas: json_data = json_data.replace("\n", "") dict_data = json.loads(json_data) url = dict_data['url'] cms = dict_data['cms'] server = dict_data['server'] statuscode = dict_data['statuscode'] length = dict_data['length'] title = dict_data['title'] row_data = [url, cms, server, statuscode, length, title] csv_write.writerow(row_data) print("write csv file ", csv_path, " ok")
EHole可以直接生成xlsx
大佬,用什么参数直接生成xlsx呢
非常有用,感谢