for event, element in etree.iterparse(path_to_file, tag="BlogPost"): for child in element: print child.tag, child.text element.clear()
[更新:]要获得“…之间的所有信息,作为字符串”,我想您需要以下其中一项:
for event, element in etree.iterparse(path_to_file, tag="BlogPost"): print etree.tostring(element) element.clear()
要么
for event, element in etree.iterparse(path_to_file, tag="BlogPost"): print ''.join([etree.tostring(child) for child in element]) element.clear()
甚至:
for event, element in etree.iterparse(path_to_file, tag="BlogPost"): print ''.join([child.text for child in element]) element.clear()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)