打开出错:
MalformedJson: Use JsonReader.setLenient(true) to accept malformed JSON at line1 column 1368184 path $.log.entries[41].request.postData.text
一、解决办法
用json.dumps格式化一下里面内容,保存为新文件再打开
python
import json
def modify_har(file_name):
with open(file_name, encoding='utf-8') as f:
result = f.readlines()
result_json = json.loads(result[0])
new_file = ''
file_list = file_name.split('\\')
file_list[len(file_list) - 1] = 'new_{}'.format(file_list[len(file_list) - 1])
for i in file_list:
new_file += i
new_file += '\\'
new_file = new_file[:-1]
result_json = json.dumps(result_json)
with open(new_file, 'w') as f:
f.writelines(result_json)
print("修改成功,已保存到:",new_file)
if __name__ == '__main__':
modify_har(r"C:\Users\86188\Desktop\xxx.har")