IordanouGiannis
IordanouGiannis

Reputation: 4357

Scraping elements from a Youtube video

I want to take some tags from youtube videos like the title, the number of views etc.I use BeautifulSoup for that but I want to make it faster.Here is my code:

#for the title
from BeautifulSoup import BeautifulSoup
html = re.findall('content=.*>\n\n',urllib2.urlopen(link).read())
soup = BeautifulSoup(html)
print soup.prettify()

#for the number of views
soup0 = BeautifulSoup(urllib2.urlopen(link).read())
for items in soup0.findAll('strong'):
    if re.match("^[0-9]*$", str(items).strip("<strong>").rstrip("</strong>")):
        viewcount=str(strongs).strip("<strong>").rstrip("</strong>")

Upvotes: 2

Views: 2865

Answers (1)

Manny D
Manny D

Reputation: 20744

Use google's youtube api.

Part of their example:

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

Upvotes: 7

Related Questions