• Python 解析XML


    <text >
        
    <font size="86" spacing="17" />
        率誕詭不經唐元奘法師遊西域十有七年撰
    </text>
    <text >
        率誕詭不經唐元奘法師遊西域十有七年撰
    </text>
    import xml.etree.ElementTree

    tree
    =xml.etree.ElementTree.ElementTree(file="e:\\Python\\1.xml")
    elem
    =tree.getroot()
    file
    =open("e:\\a.txt",'w')
    for a in elem.getiterator("text"):
        
    #print len(a._children)
        if len(a._children)>0:       
            
    for node in a:          
                
    if node.tail<> None:
                    node.tail.encode(
    'utf-8')
                    file.write(node.tail.encode(
    'utf-8'))
                
    #print xml.etree.ElementTree.iselement(node)
        else:
            
    if a.text<>None:
                file.write(a.text.encode(
    'utf-8'))
  • 相关阅读:
    164.Maximum Gap
    163.Missing Ranges
    162.Find Peak Element
    161.One Edit Distance
    160.Intersection of Two Linked Lists
    7.5爬取猫眼Top100电影名单
    7.5文件操作
    7.4文件操作(1)
    7.4一个失败的网易云爬虫,
    7.3数据结构(1)
  • 原文地址:https://www.cnblogs.com/warrior/p/1510714.html
Copyright © 2020-2023  润新知