What am I doing wrong?
When using what I believe to be a valid XPath expression in Python, I get
SyntaxError: invalid predicate
My code is:
import xml.etree.ElementTree as ET
data = '''<root>
<child>
<p>aaa</p>
<p>bbb</p>
</child>
</root>'''
root = ET.fromstring(data)
p_element = root.findall(".//p[text()='aaa']")
print(p_element[0].text)
Running this code produces an invalid predicate error, but I believe it is correct. I'm using Python version 3.10.0, and running this on Windows.
It seems to have something to do with the text()
part of the XPath; with that removed, it does not error.