Every time I want to add a new video to the database, I have to manually enter the channel name instead of just extracting it from the video URL itself (not to mention it's case sensitive).Well, this might not be the best way, but so far it worked for me and my purposes, I'll share it.
We only need BeautifulSoup and urllib for this, so let's import it now:
from bs4 import BeautifulSoup as bsfrom urllib.request import urlopen, Request
Now let's select some YouTube videos and open it with them:
url_input = "https://www.youtube.com/watch?v=pShj3gtYQik"url_opener = urlopen(Request(url_input, headers={'User-Agent': 'Mozilla'}))videoInfo = bs(url_opener, features="html.parser")
We already know how to extract the title from the previous post:
video_title = videoInfo.title.get_text()
Now, if you look at the page source for a YouTube video, you will end up with something like the following, which is what we want to access (in this case, from the video URL I used above):
So here we areÿ
The phenomenon and background
Introduce In the past five mo