qns_fengyusong 发表于 2018-8-9 07:55:58

python3基础学习(XML文件解析)

from xml.etree.ElementTree import parse  # 解析XML
  doc = parse('d:\\356.xml')
  # 获取根节点
  root = doc.getroot()
  # 获取根节点下面的下一节点
  for data in root.findall('data'):
  for report in data.findall('report'):
  for targets in report.findall('targets'):
  for target in targets.findall('target'):
  print('扫描ip:', end='')
  # 获取属性对应的值
  ip = target.find('ip').text
  print(ip)
页: [1]
查看完整版本: python3基础学习(XML文件解析)