【问题标题】:Crawling youtube user info抓取 youtube 用户信息
【发布时间】:2011-09-08 09:56:51
【问题描述】:

我正在尝试抓取 Youtube 以检索有关一组用户(大约 200 人)的信息。我有兴趣寻找用户之间的关系:

  • 联系人
  • 订阅者
  • 订阅
  • 他们评论了哪些视频
  • 等

我设法通过以下来源获得了联系信息:

import gdata.youtube
import gdata.youtube.service
from gdata.service import RequestError
from pub_author import KEY, NAME_REGEX
def get_details(name):
    yt_service = gdata.youtube.service.YouTubeService()
    yt_service.developer_key = KEY
    contact_feed = yt_service.GetYouTubeContactFeed(username=name)
    contacts = [ e.title.text for e in contact_feed.entry ]
    return contacts

我似乎无法获得所需的其他信息。 reference guide 表示我可以从 http://gdata.youtube.com/feeds/api/users/username/subscriptions?v=2 获取 XML 提要(对于某些任意用户)。但是,如果我尝试获取其他用户的订阅,则会收到 403 错误并显示以下消息:

用户必须登录才能访问这些订阅。

如果我使用 gdata API:

sub_feed = yt_service.GetYouTubeSubscriptionFeed(username=name)
sub = [ e.title.text for e in contact_feed.entry ]

然后我得到同样的错误。

如何在不登录的情况下获得这些订阅?应该可以,因为您无需登录 Youtube 网站即可访问此信息。

此外,似乎没有特定用户的订阅者的订阅源。这些信息是否可以通过 API 获得?

编辑

因此,这似乎无法通过 API 完成。我不得不以又快又脏的方式做到这一点:

for f in `cat users.txt`; do wget "www.youtube.com/profile?user=$f&view=subscriptions" --output-document subscriptions/$f.html; done

然后使用此脚本从下载的 HTML 文件中获取用户名:

"""Extract usernames from a Youtube profile using regex"""
import re
def main():
    import sys
    lines = open(sys.argv[1]).read().split('\n')
    #
    # The html files has two <a href="..."> tags for each user: once for an 
    # image thumbnail, and once for a text link.
    # 
    users = set()
    for l in lines:
        match = re.search('<a href="/user/(?P<name>[^"]+)" onmousedown', l)
        if match:
            users.add(match.group('name'))
    users = list(users)
    users.sort()
    print users
if __name__ == '__main__':
    main()

【问题讨论】:

    标签: python youtube gdata


    【解决方案1】:

    要在用户未登录的情况下访问用户的订阅源,用户必须选中其Account Sharing settings 下的“订阅频道”复选框。

    目前,无法通过gdata API 直接获取频道订阅者。事实上,它有一个出色的功能请求,已经开放了 3 年多!见Retrieving a list of a user's subscribers?。

    【讨论】:

      猜你喜欢
      • 2012-12-02
      • 2019-12-30
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 2018-07-15
      • 2016-05-23
      • 2020-02-04
      • 1970-01-01
      相关资源
      最近更新 更多