python lxml - modify attributes

前端 未结 2 1848
别跟我提以往
别跟我提以往 2020-12-09 16:09
from lxml import objectify, etree

root = etree.fromstring(\'\'\'


    

        
2条回答
  •  感情败类
    2020-12-09 16:33

    import lxml.etree as et
    
    tree = et.fromstring('''
    ... your xml ...
    ''')
    
    for host_ip in tree.xpath("/scenario/init/send/command[@name='CER']/avp[@name='Host-IP-Address']"):
        host_ip.attrib['value'] = 'foo'
    
    print et.tostring(tree)
    

提交回复
热议问题