From 7a66ee0dc4b24fe2bf160df5d4311f32ace33103 Mon Sep 17 00:00:00 2001 From: Felix <> Date: Thu, 9 Jan 2025 17:32:56 +0800 Subject: [PATCH] first commit --- .gitignore | 15 +++++++++++++++ main.py | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 .gitignore create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f47134 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# 忽略构建产物目录 +/build/ +/dist/ +/venv/ +# 忽略日志文件 +*.log + +# 忽略一些说明文档 +*.txt + +# 忽略源文件 +*.html + +# 忽略测试输出的文件 +*.json \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..37240d5 --- /dev/null +++ b/main.py @@ -0,0 +1,22 @@ +# -*- coding:utf-8 -*- +import json +import re + + +def htmlToJson(): + with open('index.html', encoding='utf8') as f: + fileContent = f.read() + + patList = re.findall(r'', fileContent) + data_Json = json.loads(patList[0]) + print(type(data_Json)) + print(data_Json) + return data_Json + +if __name__ == "__main__": + data = htmlToJson() + with open('data.json', 'w', encoding='utf8') as file: + # 使用json.dump()方法将字典转换为json并写入文件 + # ensure_ascii=False 保证非ASCII字符以原始形式保存 + # indent=4 设置缩进为4个空格,使输出更加易读 + json.dump(data, file, ensure_ascii=False, indent=4)