7

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

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

        xml文件已经被广泛使用在各种应用中,无论是Web应用、还是移动应用,或是桌面应用以及其他应用,几乎都会有XML文件的身影。尽管目前很多应用都不会将大量的数据保存在XML文件中,但至少会使用XML文件保存一些配置信息。

        在Python语言中需要导入xml模块或其子模块,并利用其中提供的API来操作XML文件。例如,读取XML文件需要导入xml.etree.ElementTree模块,并通过该模块的parse函数读取XML文件。

下面的例子读取了一个名为products.xml的文件,并输出了XML文件中相应节点和属性的值。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK