Save XML response from GET call using Python -
i'm trying create realtime report using api allows me grab data need , returns in xml format. want know is, after receiving response, how can save .xml file locally? or cache it, way can parse before parsing response.
import requests r = requests.get('url', auth=('user', 'pass'))
i'm using requests since it's easiest way make call in opinion. also, first question , i'm barely starting learn python, i'd appreciate if guys had little patience. thanks.
i looking @ similar question json, not sure if work same, https://stackoverflow.com/a/17519020/4821590
import requests import json solditems = requests.get('https://github.com/timeline.json') # (your url) data = solditems.json() open('data.json', 'w') f: json.dump(data, f)
if want able parse returned xml before doing stuff it, xml tree friend.
import requests import xml.etree.elementtree et r = requests.get('url', auth=('user', 'pass')) tree = et.parse(r.text) root = tree.getroot()
otherwise, jordanm has commented, save file , done it.
with open('data.xml', 'w') f: f.write(r.text)