从YouTube抓取信息

时间:2018-11-21 20:55:41

标签: javascript html

我正在尝试从YouTube抓取视频的类别,并且在处理数据时遇到了一些问题。到目前为止,我一直在尝试设置延迟,然后通过可能的链接来创建HTML集合,然后进行迭代。

但是,当我遍历集合时,与HTML集合元素相比,当循环执行并登录到控制台时,某些值是不同的。

具体来说,具有类别的集合元素在脚本循环中的记录方式有所不同。

我的代码如下:

document.getElementsByClassName("more-button style-scope ytd-video-secondary-info-renderer")[0].click()
    console.log("in the conditional")
    categories = document.getElementsByClassName("yt-simple-endpoint style-scope yt-formatted-string");
    console.log(categories);
    console.log("checking category");
    Array.prototype.forEach.call(categories, function (category) {
        console.log(category.innerText);
        if (category.innerText == "Entertainment" || category.innerText == "Gaming" || category.innerText == "Comedy") {
            isBadCategory = true;
        }
    });

任何指导将不胜感激!

0 个答案:

没有答案