Reading from another child element using Elementree

前端 未结 1 1845
说谎
说谎 2021-01-29 08:25

The code below goes through the xml files and parses them into a single csv file

from xml.etree import ElementTree as ET
from collections import defaultdict
impo         


        
相关标签:
1条回答
  • 2021-01-29 09:09

    Modify your headers line to

    headers = ['identify', 'id', 'service_code', 'rational', 'qualify', 'description_num', 'description_txt', 'set_data_xin', 'set_data_xax', 'set_data_value', 'set_data_x']
    
    p_get = tree.find('.//Phones/Get').text
    p_set = tree.find('.//Phones/Set').text
    

    and add this info to the row_data just before the line writer.writerow(row_data)

    like this:

    row_data.insert(0, p_get + '_' + p_set)
    

    Update

    row_data[0] = p_get + '_' + p_set
    
    0 讨论(0)
提交回复
热议问题