2012-01-05 5 views

答えて

4

lxmlパーサとxpath式を使用して、必要なコンテンツを取得できます。 例クリスマスのユーチューブビデオ -

import lxml 
from lxml import etree 
youtube = etree.HTML(urllib.urlopen("http://www.youtube.com/watch?v=KQEOBZLx-Z8").read()) //enter your youtube url here 
video_title = youtube.xpath("//span[@id='eow-title']/@title") //get xpath using firepath firefox addon 
print ''.join(video_title) 

'12日のtitle抽出する、のために - クリスマスキャロル

を、今必要なものは何でもコンテンツ取得するために類似したXPath式を使用します。

8
あなたは間違いなく、YouTubeのAPIを使用したい

、 C.リードは言った。このコードは、あなたのユーチューブビデオのタイトルと著者が表示されます:

import urllib 
import simplejson 

id = 'KQEOBZLx-Z8' 
url = 'http://gdata.youtube.com/feeds/api/videos/%s?alt=json&v=2' % id 

json = simplejson.load(urllib.urlopen(url)) 

title = json['entry']['title']['$t'] 
author = json['entry']['author'][0]['name'] 

print "id:%s\nauthor:%s\ntitle:%s" % (id, author, title) 

id:KQEOBZLx-Z8 
author:hooplakidz 
title:12 Days of Christmas - Christmas Carol 

を印刷しますあなただけ取得したい場合は、YouTubeのAPIを持つことができます多くは、例えば、あります関連動画とその作者は、URLで指定することができます。fields=entry(id),entry(author)

のような:それは私に多くのことができます彼らの答えをみんなにhttp://gdata.youtube.com/feeds/api/videos/4y9kjrVejOI/related?fields=entry(id),entry(author)&alt=json&v=2&prettyprint=true

関連する問題