尝试使用砂纸刮擦YouTube,没有获取数据

发布于 2025-02-11 08:20:57 字数 1399 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你与清晨阳光 2025-02-18 08:20:57

URL完全是动态的,这就是为什么您无法提取数据的原因。您必须使用诸如硒或API之类的自动化工具(YouTube提供API)。正如您现在要获取订阅数量的那样。因此,我以硒为示例

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

URL = 'https://www.youtube.com/c/JohnWatsonRooney'
driver.get(URL)
time.sleep(3)

subcriber_count=driver.find_element(By.XPATH,'//*[@id="subscriber-count"]').text
print(subcriber_count)

输出:

连接到系统上的设备无法正常运行。 (0x1f)

26.5K subscribers

The url is entirely dynamic that's why you can't pull the data. You have to use either an automation tool something like selenium or API (Youtube provides API). As you want to grab subscriptions count right now.So I use selenium as an example

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

URL = 'https://www.youtube.com/c/JohnWatsonRooney'
driver.get(URL)
time.sleep(3)

subcriber_count=driver.find_element(By.XPATH,'//*[@id="subscriber-count"]').text
print(subcriber_count)

Output:

A device attached to the system is not functioning. (0x1F)

26.5K subscribers
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文