2

Python爬虫编程思想(76): 读取与搜索XML文件

 2 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/121274165
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爬虫编程思想(76): 读取与搜索XML文件

        在上一篇文章中只讲了如何读取XML文件,这些XML文件可能是手工录入的,也可能是其他程序生成的,不过更有可能是当前的程序生成的。

        生成XML文件的方式很多,可以按字符串方式生成XML文件,也可以按其他方式生成文件。本节将介绍一种将Python语言中的字典转换为XML文件的方式。通过这种方式,可以实现定义一个字典变量,并为该变量设置相应的值,然后再将该字典变量转换为XML文件。

        将字典转换为XML文件需要使用dicttoxml模块中的dicttoxml函数,在导入dicttoxml模块之前需要先使用下面的命令安装dicttoxml模块。

pip install dicttoxml

          要注意的是,如果本机安装了多个版本的Python,一定要确认调用的pip命令是否为当前正在使用的Python版本中的pip,如果调用错了,就会将dicttoxml模块安装到其他Python版本中,而当前正在使用的Python版本还是无法导入dicttoxml模块。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK