Python3.x:将数据下载到xls时候用xml格式保存一份读取内容

时间:2024-06-08 14:37:32

Python3.x:将数据下载到xls时候用xml格式保存一份读取内容

核心代码:

import json
import xml.dom.minidom
from urllib import request, parse
from sqlalchemy import func dataDate = "2018-01-24"
url = 'http://********/ShowReport.szse?SHOWTYPE=xml&CATALOGID=1804&ENCODE=1&TABKEY=tab1&txtDate=' + dataDate
path = './1.xml'
request.urlretrieve(url, path)
file_xml = open(path, 'r', encoding='gbk').read()
# 获取数据xml格式
file_xml = file_xml.replace(
'<?xml version="1.0" encoding="GBK"?>', '<?xml version="1.0" encoding="utf-8"?>')
xmldoc = xml.dom.minidom.parseString(file_xml)
datas = xmldoc.getElementsByTagName('row')