使用文件获取内容从YouTube检索订阅者金额

时间:2015-08-04 23:07:40

标签: php dom youtube youtube-api

我正在努力获取客户YouTube频道的YouTube订阅者的实时数量。我已注册公共API密钥并启用了YouTube数据API。

如何获取页面上的确切订阅者数量? - 我一直在尝试使用file_get_contents并搜索span类但没有任何工作。我以前没用过这个功能。 - 看过YouTube API v2中的示例,使用V3应该很容易,但我不知道! - 我询问API和File_get_contents的原因是因为如果我可以使用file_get_contents并学习使用它,我可以完成许多其他任务,因此两个解决方案将是完美的!

在批评之前,我一直在搜索互联网,直到2010年才得到答案。这可能只是我的问题,但希望会出现一些解决方案......

            $page = file_get_contents('https://www.youtube.com/user/user here');
        $doc = new DOMDocument();
        $doc->loadHTML($page);

        if (!$dom->loadHTML($page)) {
            die ('Could not parse...');
        }

        $divs = $doc->getElementsByTagName('span');
        foreach($divs as $div) {
            if ($div->getAttribute('aria-labelledby') === 'yt-uix-tooltip84-arialabel') {
                 echo $div->nodeValue;
            }
        }

订阅号码保存在范围内:

<span class="yt-subscription-button-subscriber-count-branded-horizontal yt-uix-tooltip" title="210,089" tabindex="0" aria-label="210,089 subscribers" data-tooltip-text="210,089" aria-labelledby="yt-uix-tooltip84-arialabel">210,089</span>

0 个答案:

没有答案