Skip to content

Instantly share code, notes, and snippets.

@tiagocordeiro
Created October 20, 2022 16:19
Show Gist options
  • Save tiagocordeiro/e71a771a42f25eed53d687bcdad6175b to your computer and use it in GitHub Desktop.
Save tiagocordeiro/e71a771a42f25eed53d687bcdad6175b to your computer and use it in GitHub Desktop.
Pega número de views dos ultimos 30 dias de um canal do YouTube com Python
import requests
from bs4 import BeautifulSoup as bs
channel = input("Canal: ")
url = f"https://socialblade.com/youtube/c/{channel}"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
}
page = requests.get(url, headers=headers)
soup = bs(page.text, "html.parser")
video_views_last_30_days = soup.select(
"#socialblade-user-content > div:nth-child(3) > div:nth-child(3) > p:nth-child(1)"
)
print(video_views_last_30_days[0].text.split(" ")[-3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment