我正在尝试恢复视频的持续时间,但遇到了麻烦。
#YOUTUBE FEED
#download the file:
file = urllib2.urlopen('http://gdata.youtube.com/feeds/api/videos/2s0vk2wEMtA')
#convert to string:
data = file.read()
#close file because we dont need it anymore:
file.close()
#entire feed
root = etree.fromstring(data)
for entry in root:
for item in entry:
print item
当我打印项目时,我将其视为最后一个元素:
Element '{http://gdata.youtube.com/schemas/2007}duration' at 0x10c4fb7d0
但我不知道如何从中获取价值。有什么建议吗?
答案 0 :(得分:0)
media = root.find('{http://search.yahoo.com/mrss/} group') length = media.find('{http://gdata.youtube.com/schemas/2007} duration')。attrib.get(“seconds”) 打印长度