背景: 抓取数据是json格式内容,涉及敏感数据使用在线工具可能存在数据泄露风险,为确保数据安全本地转换较为安全 代码 import pandas as pd import json import datetime import os now = datetime.datetime.now() formatted_time = now.strftime("%Y-%m-%d_%H-%M-%S") # Read JSON data from a text file with permissive error handling with open('1.txt', 'r', encoding='utf-8', errors='replace') as file: json_data = json.load(file) # Extract the 'data' part from JSON data_list = json_data.get("data", []) # Convert to DataFrame df = pd.DataFrame(data_list) df.to_excel(f"{formatted_time}.xlsx", index=False)