如何从频道发布中裁剪视频发布者日期和订阅人数

2024-04-25 05:01:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着制作一个软件,从youtube网站上截取一些信息,目的是制作一个统计应用程序。你知道吗

我想问你,从youtube的视频中获取出版商日期的最佳方式是什么,以及如何从youtube频道中获取订户数量?你知道吗

我试着这么做

import requests
from bs4 import BeautifulSoup
import urllib2
import html5lib


g_data_subscriber = soup.find('span', 'deemphasize style-scope yt-formatted-string').get_text()

print g_data_subscriber

g_data_date = soup.find_all("span", {"class": "date"})

for item in g_data_date:
    print item.text

Tags: textimport目的信息datadate软件youtube
1条回答
网友
1楼 · 发布于 2024-04-25 05:01:22

所以这可以通过几种不同的方式来实现。我在python3.5中为此编写了一些代码。我首先去youtube频道的url获取订户数量。然后在下一个区块中,我转到一个视频url以获取“发布日期”。你知道吗

import requests
from bs4 import BeautifulSoup

#get exact subscriber count from a channel
channel_name = "FirstWeFeast"
channel_url = 'https://www.youtube.com/user/' + channel_name
r  = requests.get(channel_url)
soup = BeautifulSoup(r.text, 'html.parser')
subscriber_count = soup.find('span', 'yt-subscription-button-subscriber-count-branded-horizontal subscribed yt-uix-tooltip').get_text()
print(subscriber_count)

#get video publish date
video_url  = 'https://www.youtube.com/watch?v=eCEG4QyQbF4'
r  = requests.get(video_url)
soup = BeautifulSoup(r.text, 'html.parser')
date_info = soup.find('strong', 'watch-time-text').get_text()
publish_date = date_info.replace("Published on ", "")

print(publish_date)

相关问题 更多 >