Tac*_*ons 2 python youtube youtube-api youtube-data-api
如何从给定的URL中的python代码中获取youtube标题和描述.是否有必要使用youtube API?我正在编写一个程序,需要从给定的URL中查找生成标题和描述
这没有必要,但它可能比编写自己的更快更容易.
有关详细信息,请参阅https://developers.google.com/youtube/1.0/developers_guide_python
安装gdata模块后,试试吧
import gdata.youtube
import gdata.youtube.service
yt_service = gdata.youtube.service.YouTubeService()
# authorize - you need to sign up for your own access key, or be rate-limited
# yt_service.developer_key = 'ABCxyz123...'
# yt_service.client_id = 'My-Client_id'
def PrintEntryDetails(entry):
print 'Video title: %s' % entry.media.title.text
print 'Video published on: %s ' % entry.published.text
print 'Video description: %s' % entry.media.description.text
print 'Video category: %s' % entry.media.category[0].text
print 'Video tags: %s' % entry.media.keywords.text
print 'Video watch page: %s' % entry.media.player.url
print 'Video flash player URL: %s' % entry.GetSwfUrl()
print 'Video duration: %s' % entry.media.duration.seconds
for entry in yt_service.GetTopRatedVideoFeed().entry:
PrintEntryDetails(entry)
Run Code Online (Sandbox Code Playgroud)
两个答案都不再适用于第一个,因为 V2 API 不再可用,另一个因为 URL 资源不再可用。
这是一个有效的 V3 代码:
from apiclient.discovery import build
DEVELOPER_KEY = 'your api key goes here'
youtube = build('youtube', 'v3', developerKey=DEVELOPER_KEY)
ids = '5rC0qpLGciU,LgbuxTfJFr0'
results = youtube.videos().list(id=ids, part='snippet').execute()
for result in results.get('items', []):
print result['id']
print result['snippet']['description']
print result['snippet']['title']
Run Code Online (Sandbox Code Playgroud)