2013-02-20 118 views
0

這裏是獲取YouTube視頻的評論,從https://developers.google.com/youtube/2.0/developers_guide_protocol_comments採取的API響應:檢索YouTube上的時間戳評論

<feed> 
    <entry> 
    ... 
    <media:group> 
     ... 
    </media:group> 
    <gd:comments> 
     <gd:feedLink 
     href='https://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments'/> 
    </gd:comments> 
    </entry> 
</feed> 

我不知道要使用的API來獲取這些數據。我用Python編寫了我的代碼,它給了我一個視頻的作者姓名和評論。我想爲我的研究工作獲取每條評論的時間戳。

+0

... ... 這是API響應 – user2070040 2013-02-20 23:05:52

回答

0

那麼,這將有助於看到您使用的代碼來獲取作者和評論文本,所以我可以給你實際的代碼。但如果沒有這些,查看API響應,每個評論都位於頂級<feed>標記下的<entry>標記中。

對於每條評論,都有一個帶有時間戳的<published><updated>標記。我猜這些是原始評論的日期和最後編輯的日期。如果我有你的代碼,看看你是如何解析xml開始的,我可以添加一個代碼片段來檢索它們。

編輯:給定代碼在下面的鏈接。這是主循環的一個修改,它應該可以做你想做的事情。

for comment in comments_generator(client, VIDEO_ID): 
     author_name = comment.author[0].name.text 
     text = comment.content.text 

     post_date = comment.published.text 
     last_update_date = comment.update.text    

     print("{}(date:{}): {}".format(author_name, post_date, text)) 

請注意,日期爲文本格式。如果您想從中提取python datetime對象,請查看dateutilthis question

+0

http://code.google.com/p/amar-youtube-sentiment/source/browse/comments_YT2.1.py – user2070040 2013-02-21 00:28:52

+0

這裏是我的代碼,看看! – user2070040 2013-02-21 00:29:41

+0

回溯(最近通話最後一個): 文件 「comments_YT2.12.py」 37行,在 LAST_UPDATE_DATE = comment.update.text AttributeError的: 'YouTubeVideoCommentEntry' 對象有沒有屬性 '更新' – user2070040 2013-02-21 04:40:02