Ich habe diesen Service, den ich anrufe und es gibt mir Daten im XML-Format zurück. Ich möchte die Serveradresse daraus extrahieren. Wie kann ich das machen? Das ist, was ich bekomme, wenn ich vom Service anrufe.Wie extrahiert man Daten im XML-Format?
from xml.dom import minidom
import requests
url="http://172.10.3.2:51106/GetConnectionStrings.asmx"
#headers = {'content-type': 'application/soap+xml'}
headers = {'content-type': 'text/xml'}
body = """<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<DatabaseConnectionString xmlns='http://tempuri.org/'>
<DatabaseName>ELMA</DatabaseName>
<ApplicationName>MonitoringSystem</ApplicationName>
</DatabaseConnectionString>
</soap:Body>
</soap:Envelope>"""
response = requests.post(url,data=body,headers=headers)
#print response.content
doc = minidom.parseString(response.content)
# doc.getElementsByTagName returns NodeList
name = doc.getElementsByTagName("DatabaseConnectionStringResult")[0]
print(name.firstChild.data)
Dies ist, was ich bisher versucht habe.
Data Source=172.10.3.3;Initial Catalog=Elma;User ID=User11021969;Password=ILoveMyMOM;MultipleActiveResultSets=True;Min Pool Size=5;Max Pool Size=5000;Connect Timeout=180;Application Name=MonitoringSystem
Ich möchte die Datenquelle 172.10.3.3 extrahieren und als String speichern.
Was ist der Wert von "response.content"? –
[Duplizieren] (http://stackoverflow.com/questions/1912434/how-do-i-parse-xml-in-python) –
Versuchen 'feedparser' Modul, es ist hilfreich und bequem. – Acepcs