17 Dec
2017
17 Dec
'17
6:53 p.m.
Hi, I am not able to find the 'rab' node using the following code. Could anybody help me understand why it is the case? $ cat ./main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: from lxml import etree import sys from StringIO import StringIO tree = etree.parse(StringIO('<foo><bar><rab>abc</rab></bar><mybar>xyz</mybar></foo>')) r = tree.xpath('/foo') print len(r) print r[0].find('bar').tag print r[0].find('rab') print r[0].find('mybar') print r[0].find('nobar') $ ./main.py 1 bar None <Element mybar at 0x1082416c8> None -- Regards, Peng