N
N
Niko True2014-01-17 19:08:22
Python
Niko True, 2014-01-17 19:08:22

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

1 answer(s)
L
leclecovich, 2014-01-17
@buloshnik

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 question

Ask a Question

731 491 924 answers to any question