修改后的代码如下所示:
import json
import os
import pandas as pd
print("✨ 准备读取数据……")
with open('input/hello.json', 'r', encoding='utf-8') as file:
data = json.load(file)
functions = [item['函数名'] for item in data['triples']]
print("✅ 读取数据完成!")
output_folder = 'output'
results = []
print("✨ 准备检查数据……")
for filename in os.listdir(output_folder):
if filename.endswith('.xlsx'):
file_path = os.path.join(output_folder, filename)
df = pd.read_excel(file_path, engine='openpyxl')
for index, row in df.iterrows():
vulnerability_description = row['漏洞简介']
print("扫描 - 漏洞名称: " + row['漏洞名称'] + " CNNVD编号: " + row['CNNVD编号'])
for func in functions:
if func in vulnerability_description:
results.append({
'漏洞名称': row['漏洞名称'],
'CNNVD编号': row['CNNVD编号'],
'函数名': func
})
with open('output_vul/v_hello.json', 'w', encoding='utf-8') as file:
json.dump(results, file, ensure_ascii=False, indent=4)
print("✅ 写入JSON文件完成!")
修改后的代码将结果保存为JSON格式文件,并命名为v_hello.json
,同时保证了中文字符的正常显示。
内容由零声教学AI助手提供,问题来源于学员提问