I am running the following code in Python 2.7.3 on Mac OS X 10.6.8.
import StringIO
from lxml import etree
f = open('./foo', 'r')
doc = ""
while 1:
line = f.readline()
doc += line
if line == "":
break
tree = etree.parse(StringIO.StringIO(doc), etree.HTMLParser())
r = tree.xpath('//foo')
for i in r:
for j in i.iter():
print j.tag, j.text
And the file foo contains
<foo> AAA <bar> BBB </bar> XXX </foo>
The output is
foo AAA
bar BBB
Why am I not getting the text XXX? How do I access it?
Thanks