【问题标题】:How to get Youtube Channel Name using querySelectorAll?如何使用 querySelectorAll 获取 Youtube 频道名称?
【发布时间】:2020-09-12 11:41:42
【问题描述】:

OUTPUT : Console

网址: https://www.youtube.com/feed/trending?gl=IN

document.querySelectorAll('a[class="yt-simple-endpoint style-scope yt-formatted-string"]')[0].innerText;

document.querySelectorAll('a[class="yt-simple-endpoint style-scope yt-formatted-string"]')[1].innerText;

问题: 为什么控制台上的 OUTPUT 中有重复项(单击上图)?有人可以解释这里发生了什么吗?如何检索唯一频道名称?

【问题讨论】:

    标签: javascript google-chrome youtube selectors-api


    【解决方案1】:

    试试这个:

    document.querySelectorAll('#meta a.yt-simple-endpoint.style-scope.yt-formatted-string')[1].innerText;
    

    中还有另一个隐藏元素,其 id 为“channel-info”,具有相同的类集。您可以按 F12 然后按 CTRL-F 搜索该组类以查看重复项。

    【讨论】:

      猜你喜欢
      • 2013-07-22
      • 2018-10-28
      • 2018-04-16
      • 2014-11-17
      • 1970-01-01
      • 2020-11-26
      • 2017-04-10
      • 2021-07-11
      • 2023-04-03
      相关资源
      最近更新 更多