-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube.py
27 lines (19 loc) · 753 Bytes
/
youtube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# importing the libraries
from bs4 import BeautifulSoup
import requests
# creating function
def scrape_youtube_info(url):
# getting the request from url
r = requests.get(url)
# converting the text
s = BeautifulSoup(r.text, "html.parser")
# finding meta info for title
title = s.find("span", class_="watch-title").text.replace("\n", "")
# finding meta info for views
views = s.find("div", class_="watch-view-count").text
# finding meta info for likes
likes = s.find("span", class_="like-button-renderer").span.button.text
# saving this data in dictionary
data = {'title':title, 'views':views, 'likes':likes}
# returning the dictionary
return data