1、获取目录参考文档 手动获取密码的方法
因为有点麻烦所以写了个脚本
2、安装依赖
pip install keyring
pip install xml.etree.ElementTree
3、运行代码
import keyring
import os
import xml.etree.ElementTree as ET
# 指定文件夹路径 参考 /Users/用户名/Library/Application Support/JetBrains/DataGrip版本/options/dataSources
folder_path = '/Users/用户名/Library/Application Support/JetBrains/DataGrip版本/options/dataSources'
# 遍历文件夹下的所有文件
for filename in os.listdir(folder_path):
if filename.endswith('.xml'):
file_path = os.path.join(folder_path, filename)
# 解析XML文件
tree = ET.parse(file_path)
root = tree.getroot()
# 查找dataSource的name参数
for element in root.iter('dataSource'):
name = element.get('name')
# 通过名称获取登录凭据
credential = keyring.get_credential('IntelliJ Platform DB — ' + os.path.splitext(filename)[0], '')
# 打印密码
print(f"文件名: {filename}, 账户名称: {name} 密码: {credential.password}")