Answer the question
In order to leave comments, you need to log in
How can Python get data from a tag that doesn't close?
Hello.
I'm just starting to learn python, the question is that I can't figure out how to get data from a tag that doesn't close.
Example:
How to teach the number that is in pressure?
I know that I need to use xml.dom.minidom, but it doesn't work. I did it through regular expressions, but in my opinion it's a crutch)))
Thank you in advance for your help.
Answer the question
In order to leave comments, you need to log in
Unfortunately, you did not see an example, but I think that you meant an unpaired tag.
from xml.dom import minidom
xml_string = '<closed_tag><single_tag key="value"/></closed_tag>'
xmldoc = minidom.parseString(xml_string)
itemlist = xmldoc.getElementsByTagName('single_tag')
for item in itemlist:
print item.getAttribute('key')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question