2

我正在尝试制作一个工具,可以从视频中获取所有评论并检索所有发表评论的用户,以使赠品更容易

现在我正在使用 Youtube API

gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments?v=2&alt=json&start-index=1

我只是做了一个简单的循环,每次都会增加起始索引(1、22、44、66 等)以获取所有评论

问题是我现在对视频有超过 1000 条评论,所以这不起作用,例如:gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments?v=2&alt=json&start-index=1100

http://pastebin.com/ypLrFmTG

有没有办法让所有在 Youtube 视频上发表评论的用户?我为此工作了几个小时以了解 Youtube api 的工作原理,但这个问题使整个事情变得毫无用处

我应该使用 curl 还是其他方式来获取这些页面上的内容:youtube.com/all_comments?threaded=1&v=VIDEO_ID&page=x

4

1 回答 1

3

好吧,有几种方法。第一个是您发布的sandracires 链接。如果您查看他们的 javascript,然后将其拆分(或者只是查看 fiddler 中的流量),它会访问其站点上的 comments.php 页面并传入页码。URL 格式为:http ://www.sandracires.com/en/client/youtube/comments.php?v=videoID&page=1 。但是,我不确定它的合法性,所以我不推荐它。

我在 Youtube 本身上使用了 Fiddler,这就是我想出的。

http://youtube.com/watch_ajax?action_get_comments=1&v=videoID&p=4&commentthreshold=-5&commenttype=everything&last_comment_id=teKFzQ8cbHNiI0ouIIqSS7lHeH2TZ8eWGlW-0D0Fx5U&page_size=500&source=w

  • v = 视频 ID
  • p = 页码
  • 评论阈值 = ???
  • commenttype = 评论类型(一切都是我所知道的唯一枚举值)
  • last_comment_id = 在要加载的之前评论
  • page_size = 要返回的评论数量
  • 来源 = ??? (也许 w 用于网络)

您也许可以删除源参数和其他参数。

我不完全确定这些是否都正确。我认为p 是页码,这将允许您在没有last_comment_id参数的情况下提取评论(它对我来说就像这样)。last_comment_id通过解析生成的 XML 并找到?lc=LASTCOMMENTIDHERE.

似乎一次最多有500个。是的,我尝试过 501。正如我所指出的,数据以 XML 格式返回。每条评论如下所示:

<div class="content clearfix">
  <p class="metadata">
    <span class="author ">
      <a href="/user/mindmonkey00" class="g-hovercard yt-uix-sessionlink yt-user-name " data-sessionlink="ei=-LFcUvCPNsn-sAf7jIGgAg" dir="ltr" data-ytid="UCAufDxGRQh_LlF5tD6StNtw" data-name="">mindmonkey00</a>
    </span>
      <span class="time" dir="ltr">
        <a dir="ltr" href="http://www.youtube.com/comment?lc=teKFzQ8cbHNkP8a89kiIEtWqiTRiAkKtSnvEHB_hXG4">
          3 weeks ago
        </a>
      </span>
  </p>


  <div class="comment-text" dir="ltr">
    <p>You didn&#39;t answer my question?</p>

  </div>

  <div class="comment-actions">
    <button onclick=";return false;" type="button" class="start comment-action create-channel-lightbox yt-uix-button yt-uix-button-link yt-uix-button-size-default" data-upsell="comment" role="button"><span class="yt-uix-button-content">Reply </span></button>
    <span class="separator">&middot;</span>


    <span ><button title="Vote Up" onclick=";return false;" type="button" class="start comment-action-vote-up comment-action yt-uix-button yt-uix-button-link yt-uix-button-size-default yt-uix-button-has-icon yt-uix-tooltip yt-uix-button-empty" data-tooltip-show-delay="300" data-action="vote-up" role="button"><span class="yt-uix-button-icon-wrapper"><img class="yt-uix-button-icon yt-uix-button-icon-watch-comment-vote-up" src="//s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif" alt="Vote Up" title=""></span></button></span><span ><button title="Vote Down" onclick=";return false;" type="button" class="end comment-action-vote-down comment-action yt-uix-button yt-uix-button-link yt-uix-button-size-default yt-uix-button-has-icon yt-uix-tooltip yt-uix-button-empty" data-tooltip-show-delay="300" data-action="vote-down" role="button"><span class="yt-uix-button-icon-wrapper"><img class="yt-uix-button-icon yt-uix-button-icon-watch-comment-vote-down" src="//s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif" alt="Vote Down" title=""></span></button></span>
  </div>

</div>

请记住,通过尝试规避 Youtube 的 API 规则,您可能不得不每隔一段时间重做这个过程。他们可能会更改 URL。

于 2013-10-15T03:37:14.267 回答