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'...

修改后的代码如下所示:

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助手提供,问题来源于学员提问

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

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

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

联系我们

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

微信号:3007537140

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

关注我们
x

注册

已经有帐号?