【问题标题】:YouTube Likes using Python & BeautifulSoupYouTube Likes 使用 Python 和 BeautifulSoup
【发布时间】:2011-12-26 13:57:12
【问题描述】:

YouTube 上有很多 PHP 喜欢/不喜欢的结果,但 Python 中没有。我想使用 BeautifulSoup 来收集喜欢和不喜欢的数量,因为 YouTube-API 不包括这个。

我知道喜欢和不喜欢都包含在这个跨度类中:

<span class="watch-likes-dislikes">
<span class="likes">6</span> likes, <span class="dislikes">0</span> dislikes
        </span>

谢谢。

【问题讨论】:

  • 您是尝试通过使用 BeautifulSoup 解析页面,还是使用 Google API 来读取 YouTube 视频的点赞数?如果您编辑问题以消除多余的代码行,这对试图回答您的问题的人会有所帮助,这样他们就可以准确地看到您需要帮助的内容。

标签: python youtube beautifulsoup


【解决方案1】:

为什么不使用YouTube Data API?视频供稿包含一个

<gd:rating average='4.553648' max='5' min='1' numRaters='233' rel='http://schemas.google.com/g/2005#overall'/>

在每个&lt;entry/&gt;内。

【讨论】:

【解决方案2】:

我认为 HTML 现在看起来与您提供的不同。以下是我如何获得截至 2017 年 2 月的点赞数:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import urllib2
import html5lib
from bs4 import BeautifulSoup
url = "https://www.youtube.com/watch?v=DNMlW_5Bmv4"
page = urllib2.urlopen(url)
soup = BeautifulSoup(page, 'html5lib')
soup.find("button",attrs={"title": "I like this"}).get_text()
# as of now, the number of upvote is 3240

# dislike is similar:
soup.find("button",attrs={"title": "I dislike this"}).get_text()
# which is 24 by now

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-21
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 2019-07-24
    相关资源
    最近更新 更多