# -*- 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)