
Feb. 10, 2018
5:07 p.m.
Hi, I'd like to extract the lowest level of the match. Is possible with xpath()? Thanks. $ 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('<div><div>abc</div></div>')) r = tree.xpath('//div[starts-with(., "a")]') for x in r: print etree.tostring(x) $ ./main.py <div><div>abc</div></div> <div>abc</div> -- Regards, Peng