如何裁剪视频发布者日期和频道发布者的订阅者数量

时间:2017-08-01 21:13:21

标签: python youtube request bs4

我尝试制作一个软件,用于从网站中裁剪一些信息,指定是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

1 个答案:

答案 0 :(得分:0)

所以这可以通过几种不同的方式完成。我在Python 3.5中编写了一些适用于此的代码。我首先访问youtube频道网址以获取订阅者数量。然后在下一个区块中,我转到一个视频网址,以便在#34;上发布"日期。

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)