3

Python爬虫编程思想(77): XML字符串转换为字典

 2 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/121274230
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Python爬虫编程思想(77): XML字符串转换为字典

        将XML字符串转换为字典是上一节讲的将字典转换为字符串的逆过程,需要导入xmltodict模块,首先,需要使用下面的命令安装xmltodict模块,注意事项与按dicttoxml模块类似。

pip install xmltodict

        下面的例子从products.xml文件中读取一个XML字符串,并使用xmltodict模块的parse函数分析这个XML字符串,如果XML格式正确,parse函数会返回与该XML字符串对应的字典对象。

程序运行结果如下所示:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK