这是将XML名称空间与 ElementTree 一起使用的示例:
>>> x = '''<channel xmlns:media="http://www.w3.org/TR/html4/"> <title>Popular Photography in the last 1 week</title> <item> <title>foo</title> <media:category label="Miscellaneous">photography/misc</media:category> <media:content url="http://foo.com/1.jpg" height="375" width="500" medium="image"/> </item> <item> ... </item></channel>'''>>> node = ElementTree.fromstring(x)>>> for elem in node.findall('item/{http://www.w3.org/TR/html4/}category'): print elem.textphotography/misc
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)