如何从 youtube/v3/channels API 获取 Youtube 频道的链接(网站)?

问题描述 投票:0回答:2

查看文档:

https://developers.google.com/youtube/v3/docs/channels/list

我没有看到任何请求获取频道链接或网站的部分。如果您在 API 之外访问其正常网站上的任何频道“关于”页面,它会在名为“链接”的部分中列出该频道的外部网站。

有没有办法要求谷歌添加这个?

google-api youtube-api youtube-data-api
2个回答
3
投票

YouTube Data API v3 再次不提供基本功能。

我建议您尝试我的开源YouTube操作API。事实上,通过获取 https://yt.lemnoslife.com/channels?part=about&id=CHANNEL_ID,您将在

About
中检索给定 YouTube 频道的
item["links"]
部分的链接。

YouTube 频道示例 (

UC9-y-6csu5WGm29I7JiwpnA
) 在其
About
选项卡中包含此类网站 URL。我的 API 将返回它:

{
    "kind": "youtube#channelListResponse",
    "etag": "NotImplemented",
    "items": [
        {
            "kind": "youtube#channel",
            "etag": "NotImplemented",
            "id": "UC9-y-6csu5WGm29I7JiwpnA",
            "countryChannelId": "UC9-y-6csu5WGm29I7JiwpnA",
            "about": {
                "stats": {
                    "joinedDate": 1239321600,
                    "viewCount": 201152616,
                    "subscriberCount": 2320000
                },
                "description": "Videos all about computers and computer stuff. Sister channel of Numberphile.",
                "title": "Computerphile",
                "details": {
                    "location": null
                },
                "links": [
                    {
                        "url": "http:\/\/www.facebook.com\/computerphile",
                        "title": "Facebook"
                    },
                    {
                        "url": "https:\/\/twitter.com\/computer_phile",
                        "title": "Twitter"
                    }
                ],
                "handle": "@Computerphile"
            }
        }
    ]
}

0
投票

这里有一个 Python3.9 脚本,无需 Youtube 数据 API,只需使用 Playwright 抓取页面即可完成此操作。 请随意改进它,我仍然是 Python 新手(并且 Playwright 文档中不鼓励使用 element_handles )。

它还使用此

URLSearchParams Python Module 来清理每个相关内容链接的 url(太长了:https://www.youtube.com/redirect?event=channel_description&redir_token=QUFFLUhqa3pPZENEajNSQTBiSU41eEhtYzhBREpST2RvUXxBQ3Jtc0tsSEhFQ3ZhSzN nQmdDUWNYd0NZZHZXRldmVUpVcnNmZEw5dXRBR1Y5dDl4ZG5RZ0p6YkQtTmh1WlI3TTRpbkRTb3NoZ2x3SmhYM0tMdzdwUmV1akRtc0IxaUdrZ3J4akF6cWQ4YldWdlZ4VDZpNy1VSQ &q=https%3A%2F% 2Ftsuki.market%2Fcollections%2Fbasics-预购 )

参数

_str_youtube_url

是关于部分的频道的URL(例如
https://www.youtube.com/@PewDiePie/about

from playwright.sync_api import sync_playwright from URLSearchParams import URLSearchParams def get_youtube_channel_related_content(_str_youtube_url): lst_related_content_links = [] try: with sync_playwright() as p: browser = p.chromium.launch() context = browser.new_context(ignore_https_errors=True, user_agent='your_user_agent' ) page = context.new_page() page.goto(_str_youtube_url) # clicking Yes on GDPR message (in french) page.get_by_role("button", name="Tout accepter").click() page.wait_for_selector('#links-container') # Selecting the links-container div links_container = page.locator('#links-container a') if links_container.count() > 0: for element in links_container.element_handles(): if element.get_attribute('href') != None: lst_related_content_links.append(URLSearchParams(element.get_attribute('href')).get('q')) browser.close() return lst_related_content_links except Exception as ex: ...
    
© www.soinside.com 2019 - 2024. All rights reserved.