在您的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'
來源
2011-11-11 06:26:56
jfs
謝謝JF現在它只是搞清楚在什麼地方 '目錄(entry.rating)' https://www.stypi.com/davidneudorfer/youtube。 py –
@David Neudorfer:如果你不知道「Run'python'」是什麼意思,那麼至少應該從書[Learn Python The Hard Way]中學習[Exercise 0:The Setup](http://learnpythonthehardway.org/) )。 – jfs
no no我有上述腳本的工作在: https://www.stypi.com/davidneudorfer/watch_likes_dislikes.py 但我不知道如何將它與我的主腳本合併: https:// www .stypi.com/davidneudorfer/youtube.py 任何建議都會很棒。 –