前言
同样的套路又来了,继续尝试从配置文件中读取敏感的信息,这次轮到的是MySQL-Front。
MySQL-Front就一款开源的mysql管理工具,官方网站http://munity-nt"></manualurl> <connection> <database></database> <host>127.0.0.1</host> <library> <filename>libMySQL.dll</filename> <tunnel_url></tunnel_url> </library> <password encode="none">root</password> <port>3306</port> <user>root</user> </connection> <favorites /> </account> <account name="daqin"> <lastlogin>0</lastlogin> <manualurl version=""></manualurl> <connection> <database></database> <host>127.0.0.1</host> <library> <filename>libMySQL.dll</filename> <tunnel_url></tunnel_url> </library> <password encode="none">daqin</password> <port>3306</port> <user>daqin</user> </connection> <favorites /> </account></accounts>
python处理XML、HTML的利器PyQuery
我出于要练习的目的,想要用python的XML标准库处理XML ,但是发python 内置提供了好几种方法:xml.sax xml.dom xml.minidom
以及还有xml.parsers.expat ,选择太多,还是决定用PyQuery,PyQuery是依赖于lxml实现的jquery风格的xml解析和处理库。
lxml算是python很重要的库了,已知pandas,BeautifulSoup等等这些库有部分功能依赖lxml。
输入命令安装即可:
pip install pyquery
看完教程后就能把代码写出来了↓↓↓
python3 读取 MySQL-Front 的密码:
# -*- coding: utf-8 -*-"""Created on 2017-04-22 22:53:35@author: codegay"""import osfrom pyquery import PyQuery as pyqxmlpath = os.environ['appdata']+r'\MySQL-Front\Accounts.xml'root = pyq(filename=xmlpath)for r in root('connection').items(): print("----------------------------------------------") print('host:',r('host').text()) print('username:',r('user').text()) print('password:',r('password').text())运行代码后输出:
----------------------------------------------host: 127.0.0.1username: rootpassword: root----------------------------------------------host: 127.0.0.1username: daqinpassword: daqin以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!