如何使用 python 代码从给定的 url 获取 youtube 标题和描述? [英] How do I fetch youtube title and description from given url using python code?

查看:39
本文介绍了如何使用 python 代码从给定的 url 获取 youtube 标题和描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从给定 url 的 python 代码中获取 youtube 标题和描述.是否有必要为此使用 youtube API?我正在编写一个程序,需要从给定的 url 中找到生成标题和描述

How do I fetch youtube title and description from python code from the given url. Is it necessory to use youtube API for it? I am writing a program which need to find generate title and description from given url

推荐答案

它不是必需,但它可能比编写自己的方案更快、更容易.

It is not necessary, but it is probably significantly quicker and easier than writing your own.

有关详细信息,请参阅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)

这篇关于如何使用 python 代码从给定的 url 获取 youtube 标题和描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆