【问题标题】:Scraping elements from a Youtube video从 Youtube 视频中抓取元素
【发布时间】:2021-05-19 02:55:16
【问题描述】:

我想从 youtube 视频中获取一些标签,例如标题、观看次数等。我为此使用 BeautifulSoup,但我想让它更快。这是我的代码:

#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>")

【问题讨论】:

  • 好吧,它真的很慢吗?

标签: python beautifulsoup


【解决方案1】:

使用google's youtube api

他们的部分例子:

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

【讨论】:

猜你喜欢
  • 2014-01-28
  • 1970-01-01
  • 2015-08-23
  • 2019-12-30
  • 2016-11-14
  • 2017-03-10
  • 2020-10-04
  • 1970-01-01
  • 2017-04-28
相关资源
最近更新 更多