Easy way to get data between tags of xml or html files in python?
html, python, xml
Solution
without external modules, eg
>>> myhtml = """ <tag>I need this stuff</tag>
... blah blah
... <tag>I need this stuff too
... </tag>
... blah blah """
>>> for item in myhtml.split("</tag>"):
... if "<tag>" in item:
... print item [ item.find("<tag>")+len("<tag>") : ]
...
I need this stuff
I need this stuff too
Problem
I am using Python and need to find and retrieve all character data between tags: ``` <tag>I need this stuff</tag> ``` I then want to output the found data to another file. I am just looking for a very easy and efficient way to do this. If you can post a quick code snippet to portray the ease of use. Because I am having a bit of trouble understanding the parsers.