I’m trying to parse out some XML, where some tags aren’t always in the XML. I was getting an error when trying to get the text, as I can’t get .text when it’s None
Seems like there should be a better way to handle this? This is also just one value, I have many that I need to extract I don’t think repeating the XML Path is great solution
This returns “” if value is None and returns the actual text if exists:
value = "" if properties.find("link[@title='myTitle']/a:inline/feed/entry/content/b:properties/c:Id", namespaces) is None else properties.find("link[@title='myTitle']/a:inline/feed/entry/content/b:properties/c:Id", namespaces).text
JAM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.