您可以使用根节点的getchildren()或iterdescendants()方法获取ElementTree节点的子节点:
>>> from lxml import etree>>> from cStringIO import StringIO>>> t = etree.parse(StringIO("""<body>... <h1>A title</h1>... <p>Some text</p>... </body>"""))>>> root = t.getroot()>>> for child in root.iterdescendants(),:... print etree.tostring(child)...<h1>A title</h1><p>Some text</p>可以简写如下:
print ''.join([etree.tostring(child) for child in root.iterdescendants()])



