我正在尝试使用iterparse()
of解析 iTunes 播放列表,ElementTree
但出现以下错误:
AttributeError: 'Element' object has no attribute 'xpath'
代码如下:
import xml.etree.ElementTree as ET
context = ET.iterparse(file,events=("start", "end"))
# turn it into an iterator
context = iter(context)
# get the root element
event, root = context.next()
for event, elem in context:
z = elem.xpath(".//key")
elem.clear()
root.clear()
print z
我做错了什么?文件太大,所以iterparse()
无论如何我都必须使用。