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)
发布评论
评论(1)
URL完全是动态的,这就是为什么您无法提取数据的原因。您必须使用诸如硒或API之类的自动化工具(YouTube提供API)。正如您现在要获取订阅数量的那样。因此,我以硒为示例
输出:
连接到系统上的设备无法正常运行。 (0x1f)
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
Output:
A device attached to the system is not functioning. (0x1F)