Reputation: 151
My code return XML response, i want to print only link that contain https
like this:
https://xxxx.xxxx.com/playback/presentation/5
Ex of response:
<playback>
<format>
<type>presentation</type>
<url>https://xxxx.xxxx.com/playback/presentation/5</url>
<processingTime>915</processingTime>
<length>0</length>
<size>114961</size>
<preview>
I tried this:
x = re.search("<url>.{45}", full_responsee).group()
xx = x.replace('<url>', '')
soup = xx
print(x)
But i need solution more simple.
Any kind of help please?
Upvotes: 0
Views: 204
Reputation: 49893
Assuming the url
element only appears once & without any attributes, this will do the trick:
full_responsee.split("<url>")[1].split("</url>")[0]
Upvotes: 1
Reputation: 176
You can use ElementTree and do this
from xml.etree import ElementTree as et
tree = et.parse(your-xml)
url = tree.find('playback/format/url')
print(url)
and if you want to change the value:
tree.find('url').text = "newValue"
Upvotes: 1