I need to check whether a certain tag exists in an xml file.
For example, I want to see if the tag exists in this snippet:
Assume you want to get elem2's value, you can use xpath to find it.
tree = etree.parse(StringIO(htmlString), etree.HTMLParser()).getroot() youWantValue = tree.xpath('/main/elem2')[0].text