Another way that looks more straightforward to me:
results = []
root = lxml.hmtl.fromstring(the_html_above)
for tag in root.iter():
if "TEXT A" in tag.text
results.append(tag)
You are very close. Use text()=
rather than @text
(which indicates an attribute).
e = root.xpath('.//a[text()="TEXT A"]')
Or, if you know only that the text contains "TEXT A",
e = root.xpath('.//a[contains(text(),"TEXT A")]')
Or, if you know only that text starts with "TEXT A",
e = root.xpath('.//a[starts-with(text(),"TEXT A")]')
See the docs for more on the available string functions.
For example,
import lxml.html as LH
text = '''\
<html>
<body>
<a href="/1234.html">TEXT A</a>
<a href="/3243.html">TEXT B</a>
<a href="/7445.html">TEXT C</a>
<body>
</html>'''
root = LH.fromstring(text)
e = root.xpath('.//a[text()="TEXT A"]')
print(e)
yields
[<Element a at 0xb746d2cc>]