ZBLOG

import json import os import pandas as pd import chardet print("✨ 准备读取数据……") # with open('hello.json', 'r') as file: # #data = json.load(file) # data = json.load(file, encoding='utf-8') with open('input/hello.json', 'r', encoding='utf-8'...

修改后的代码如下所示:

  1. import json
  2. import os
  3. import pandas as pd
  4. print("✨ 准备读取数据……")
  5. with open('input/hello.json', 'r', encoding='utf-8') as file:
  6. data = json.load(file)
  7. functions = [item['函数名'] for item in data['triples']]
  8. print("✅ 读取数据完成!")
  9. output_folder = 'output'
  10. results = []
  11. print("✨ 准备检查数据……")
  12. for filename in os.listdir(output_folder):
  13. if filename.endswith('.xlsx'):
  14. file_path = os.path.join(output_folder, filename)
  15. df = pd.read_excel(file_path, engine='openpyxl')
  16. for index, row in df.iterrows():
  17. vulnerability_description = row['漏洞简介']
  18. print("扫描 - 漏洞名称: " + row['漏洞名称'] + " CNNVD编号: " + row['CNNVD编号'])
  19. for func in functions:
  20. if func in vulnerability_description:
  21. results.append({
  22. '漏洞名称': row['漏洞名称'],
  23. 'CNNVD编号': row['CNNVD编号'],
  24. '函数名': func
  25. })
  26. with open('output_vul/v_hello.json', 'w', encoding='utf-8') as file:
  27. json.dump(results, file, ensure_ascii=False, indent=4)
  28. print("✅ 写入JSON文件完成!")

修改后的代码将结果保存为JSON格式文件,并命名为v_hello.json,同时保证了中文字符的正常显示。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=13910

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?