gpt4 book ai didi

python - YouTube的Python平均评分

转载 作者:行者123 更新时间:2023-12-03 06:04:00 25 4
gpt4 key购买 nike

如何使用Python YouTube GData API调用gd:rating XML文件?

我将YouTube video_id作为变量,并且我知道可以返回以下内容:

<gd:rating average='4.553648' max='5' min='1' numRaters='233' rel='http://schemas.google.com/g/2005#overall'/>

我只是不知道如何在Python中做到这一点。

最佳答案

previous question中,您已经演示了使用video_id检索条目的代码。

运行python:

>>> from gdata.youtube.service import YouTubeService
>>> yt = YouTubeService()
>>> entry = yt.GetYouTubeVideoEntry(video_id='pP9VjGmmhfo')
>>> entry.rating
<gdata.youtube.Rating object at 0x2722cd0>
>>> print entry.rating
<?xml version='1.0' encoding='UTF-8'?>
<ns0:rating average="4.4662576" max="5" min="1" numRaters="652" rel="http://schemas.google.com/g/2005#overall" xmlns:ns0="http://schemas.google.com/g/2005" />
>>> entry.rating.average
'4.4662576'
>>> entry.rating.numRaters
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Rating' object has no attribute 'numRaters'
>>> dir(entry.rating)
['FindExtensions', 'ToString', '_AddMembersToElementTree', '_BecomeChildElement', '_ConvertElementAttributeToMember', '_ConvertElementTreeToMember', '_HarvestElementTree', '_ToElementTree', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_attributes', '_children', '_namespace', '_tag', 'average', 'extension_attributes', 'extension_elements', 'max', 'min', 'num_raters', 'text']
>>> entry.rating.num_raters
'652'

关于python - YouTube的Python平均评分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8088304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com