Python/スクレイピングいろいろ

Python
import requests
from bs4 import BeautifulSoup

url = "https://www.youtube.com/channel/UCEfUkoXXYgL_abnA1P90j1g"

response = requests.get(url)
soup = BeautifulSoup(response.text,'lxml')


h1 = soup.find('h1').get_text()
print(h1) #Catalina & Partners


registrants = soup.find(attrs={"class", "yt-subscription-button-subscriber-count-branded-horizontal"}).get_text()
print(registrants) #1.57万


about = requests.get(url + "/about")
soup02 = BeautifulSoup(about.text,'lxml')
totalViews = soup02.select_one('span[class="about-stat"] > b')
print(totalViews.string) #6,432,971


videos = requests.get(url + '/videos')
soup03 = BeautifulSoup(videos.text,'lxml')
days = soup03.select('[class="yt-lockup-meta-info"] > li')[1].get_text()
print(day) #17 時間前

title = soup03.findAll("h3")[3].get_text()
print(title) #Tottenham hotspur NEW Warm-Up! - 長さ: 3 分 34 秒。


img = soup.findAll('img')[0]
print(img.get('src'))
#https://yt3.ggpht.com/a/AGF-l78ETdiicRLZcEngs_sFosB8QPvsSapNSDOfcQ=s100-c-k-c0xffffffff-no-rj-mo