Open OKVVbin opened 1 year ago
初步断定/无法存在于文件名的问题
加一个函数过滤一下: 修改后的代码(添加了sanitize_filename函数,修改了out_file_excel函数): def sanitize_filename(filename): validchars = f'-.()【】= {string.ascii_letters}{string.digits}"' valid_chars += ''.join(chr(i) for i in range(0x4E00, 0x9FA6) if unicodedata.category(chr(i)).startswith('L')) return ''.join(c if c in validchars else '' for c in filename)
def out_file_excel(filename, database, scan_format, fields): print(colorama.Fore.RED + "======文档输出=======") if scan_format:
out_file_scan(filename, database)
else:
field = fields.split(",") # 获取查询参数
column_lib = {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'F', 7: 'G', 8: 'H', 9: 'I', 10: 'J', 11: 'K', 12: 'L',
13: 'M', 14: 'N', 15: 'O', 16: 'P', 17: 'Q', 18: 'R', 19: 'S', 20: 'T', 21: 'U', 22: 'V', 23: 'W',
24: 'X', 25: 'Y', 26: 'Z'}
sanitized_filename = sanitize_filename(filename) # 替换无效字符
workbook = xlsxwriter.Workbook(sanitized_filename)
worksheet = workbook.add_worksheet()
worksheet.set_column('A:{}'.format(column_lib[len(field)]), 30)
title_format = workbook.add_format(
{'font_size': 14, 'border': 1, 'bold': True, 'font_color': 'white', 'bg_color': '#4BACC6',
'align': 'center',
'valign': 'center', 'text_wrap': True})
content_format = workbook.add_format({'border': 1, 'align': 'left', 'valign': 'vcenter', 'text_wrap': True})
i = 1
row = 1
col = 0
for column in field:
worksheet.write('{}1'.format(column_lib[i]), column, title_format)
i += 1
for item in database:
for n in range(len(field)):
worksheet.write(row, col + n, item[n], content_format)
row = row + 1
workbook.close()
print(colorama.Fore.GREEN + "[+] 文档输出成功!文件名为:{}".format(sanitized_filename))
感谢您对FofaMap的支持。目前Bug已定位,报错确实是因为生成的xlsx文件名含有特殊符号导致,我们将在下一个版本中针对该问题进行优化。
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Users/PycharmProjects/FofaMap/fofa_search.py", line 631, in
bat_query(bat_query_file, scan_format)
File "/Users/PycharmProjects/FofaMap/fofa_search.py", line 386, in bat_query
out_file_excel(filename, database, scan_format, fields)
File "/Users/PycharmProjects/FofaMap/fofa_search.py", line 227, in out_file_excel
workbook.close()
File "/Users/PycharmProjects/FofaMap/project/lib/python3.10/site-packages/xlsxwriter/workbook.py", line 326, in close
raise FileCreateError(e)
xlsxwriter.exceptions.FileCreateError: [Errno 2] No such file or directory: 'task-2-【ip="211.45.30.16/24"】.xlsx'