Dies ist eine alte Version des Dokuments!
from bs4 import BeautifulSoup
Importiert die Klasse
soup = BeautifulSoup(daten, Parsername)
Instanziert ein BeatifulSoup-Objekt.
Beispiel:
daten = '<?xml version="1.0" encoding="utf-8"?> <SnapshotDeviceResponse xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed5"> <crossRefIDorSnapshotData> <snapshotData> <snapshotDeviceResponseInfo> <connectionIdentifier> <callID>9</callID> <deviceID>sip:482735035@172.20.1.7</deviceID> </connectionIdentifier> <localCallState> <compoundCallState> <localConnectionState>connected</localConnectionState> </compoundCallState> </localCallState> </snapshotDeviceResponseInfo> </snapshotData> </crossRefIDorSnapshotData> </SnapshotDeviceResponse>' soup = BeautifulSoup(daten, 'xml')
soup repräsentiert anschließend den Tree.
Um ein Element im Baum anzusprechen:
soup.Element.Unterelement.Unterunterelement
Beispiel:
soup.crossRefIDorSnapshotData.snapshotData.snapshotDeviceResponseInfo.connectionIdentifier.callID <code> ==== String-Zugriff ==== * Zugriff auf die Strings zwischen Tags * Erfolgt über das Objekt "string" * ist vom Typ "NavigableString" <code> soup.Element.Unterelement.Unterunterelement.string
Beispiel:
<code> soup.crossRefIDorSnapshotData.snapshotData.snapshotDeviceResponseInfo.connectionIdentifier.callID.string <code>