# -*- coding: utf-8 -*- import requests import xmltodict import json def get_response(request_url): r = requests.get(request_url) rt = r.text return rt def xmlstr2jsonstr(xmlstr): xmlparse = xmltodict.parse(xmlstr) #dumps()方法的ident=1,格式化json jsonstr = json.dumps(xmlparse,indent=1) return jsonstr def main(request_url): xmlstr = get_response(request_url) jsonstr = xmlstr2jsonstr(xmlstr) print(jsonstr) if __name__ == ‘__main__‘: request_url = ‘‘ main(request_url)
原文地址:https://www.cnblogs.com/navysummer/p/10062461.html
时间: 2024-10-18 08:31:31