requests
non gestisce le risposte XML di analisi, no. Le risposte XML sono di natura molto più complessa delle risposte JSON, il modo in cui serializzare i dati XML in strutture Python non è così semplice.
Python è dotato di parser XML incorporati. Vi consiglio di utilizzare il ElementTree API:
import requests
from xml.etree import ElementTree
response = requests.get(url)
tree = ElementTree.fromstring(response.content)
o, se la risposta è particolarmente grande, utilizzare un approccio incrementale:
response = requests.get(url, stream=True)
# if the server sent a Gzip or Deflate compressed response, decompress
# as we read the raw stream:
response.raw.decode_content = True
events = ElementTree.iterparse(response.raw)
for event, elem in events:
# do something with `elem`
L'esterno lxml project costruisce sulla stessa API per dare più caratteristiche e potere ancora.
fonte
2013-08-19 07:33:55