I need to rewrite scripts from PowerShell to python and I'm new to python. How can I get value from XML response in python e.g
I have a response in XML:
<?xml version="1.0" encoding="utf-8"?>
<Channels resultCount="1" xmlns="urn:xmlsample:1.0">
<Channel id="01">
<Events resultCount="1">
<Event id="123456789abcdefghij"/>
</Events>
</Channel>
</Channels>
I need to get only value from Event id in response
123456789abcdefghij
In PowerShell, I added
[xml]$xml = $req
$xml.Channels.Channel.Events.Event.Id
Is there is an equivalent in python? I only find how to get value from the xml file but I need from response.
For now, I have
import requests
requestIP = 'http://192.168.0.12/channel' # enter IP
def getEventsToRecord():
body = '<SubQueryOptions xmlns="urn:xmlsample:1.0"><QueryOption path="Events">/filter/AvailabilityStart>=now()&AvailabilityEnd<now(P1D)</QueryOption></SubQueryOptions>'
r = requests.request("PUT", f'{requestIP}/Channels', data = body)
print(r.text)