• 技术文章 >Python技术 >Python基础教程

    python ElementTree解析的方法

    小妮浅浅小妮浅浅2021-06-09 09:45:32原创2702

    1、调用parse()方法,返回解析树

    tree = ET.parse('./resource/movie.xml')
    root = tree.getroot()

    2、调用from_string(),返回解析树的根元素

    data = open('./resource/movie.xml').read()
    root = ET.fromstring(data)

    3、调用 ElementTree 类的 ElementTree(self, element=None, file=None) 方法

    tree = ET.ElementTree(file="./resource/movie.xml")
    root = tree.getroot()

    以上就是pythonElementTree解析的方法,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python elementtree
    品易云
    上一篇:python XML数据是什么 下一篇:python ElementTree是什么意思

    相关文章推荐

    • python实例:用代码画五角星• python and用法• python pipenv的环境运行• python中geopy怎么用• python中PyMySQL有什么用• python中pyenv是什么

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网