问题描述
我正在尝试使用gdata获取用户的收藏夹供稿。 我所做的是:
service = gdata.youtube.service.YouTubeService()
favorites = service.GetUserFavoritesFeed(username='youtube_username').entry
for favorite in favorites:
print 'Title: %s' % favorite.media.title.text
print 'Description %s' % favorite.media.description.text
在“ favorite.media.description.text”行中,它给我一个错误,例如:
'NoneType' object has no attribute 'text'
虽然我可以毫无问题地获得标题,但为什么没有'description'的文本属性? 我可以使用'favorite.media.description'并获取描述的XML对象,但是我不能使用它。 我该如何解析? 有没有解决此问题的方法来获取描述文字? 还是我想念的东西?
1楼
我尝试与用户alexander
,它会为该用户打印大部分title/description
。
仅获得一个Private Video
的例外。
当我从python代码打印favorite.media
,它返回:
<?xml version='1.0' encoding='UTF-8'?>
<ns0:group xmlns:ns0="http://search.yahoo.com/mrss/">
<ns0:title type="plain">Private video</ns0:title>
<ns0:category label="Music" scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Music</ns0:category>
</ns0:group>
您会看到它没有任何描述。 因此,建议您在打印之前先使用支票。
if favorite.media.description != None:
print 'Description %s' % favorite.media.description.text