$$$ If you have strong keywords then you are the king of the world.$$$
Sometimes ever wondered .... how some youtubers rank their latest video right on top and it takes years and years for you to figure out what and how they must be doing it?
Sometimes you just wished if only you can take a snick peek to their used keywords or tags they use in their videos.
There are many other ways to check what keywords they must have used on a specific video. One way was simply checking "View Source" but that process consumes whole lot of time. If you have 100 videos links to check then what?
So, I have created a simple... ok not so simple but yet simple... we will keep it that way for now.
So I was saying I have created a simple script in Python that scraps all the tags of the video...
But... there was a problem.
Many people were struggling with the same issue. The issue was once you run the script it will show the keywords tags but when you run again its just blank.
So that method was not reliable.
Then I got an Idea...
What my script does is its simply get all the raw data and saves in a temp.txt file.
Then the remaining code will run and extract the tags we need and beautifully save it again in a new file called keywords_.txt.
And now it will not crash or give out blank data as before.
So mission successful.
But again... another issue....
Not all videos have "English Letters" tags / keywords
Some have Hindi, Chinese, Korean, German ... etc etc language and now that was giving ERROR
Again I got down to fix it and found another solution.
The solution was twisted but for me as long as its workings for me I just go with it.
So the solution was to encode the string what is not in English letters. As other character text cannot be printed or supported in a text file.
But if the text or keywords is in Chinese and you want to save the Chinese text in a text file and you can understand Chinese then this is the best method I would suggest but I don't understand Chinese. All I understand is Chinese Hakka Noodles lol.
Ok enough talk
Here is the code.
# Dev: Joel D'costa import re import requests from bs4 import BeautifulSoup as bs #Change this url with your youtube URL url = "https://www.youtube.com/watch?v=iuETwOrQnSw&t=1s" r = requests.get(url) soup = bs(r.content,'html.parser') #print(soup.prettify()) title = soup.title.string print(title) data = str(soup.find_all('script')) with open("temp_.txt","w") as out: out.writelines(str(data.encode("utf-8"))) out.close() def find_between( s, first, last ): try: start = s.index( first ) + len( first ) end = s.index( last, start ) return s[start:end] except ValueError: return "" with open("temp_.txt","r") as out: data = out.readlines() for i in data: j = re.findall("keywords.*",i.replace("\\","")) #print(j) count = 0 for line in j: if (count == 0): #print(re.findall('\[.*\]', line)) print ("Keywords:- "+find_between(line, "[", "]").replace('"','')) key = find_between(line, "[", "]").replace('"','') n_key = key.split(",") nn_key = len(n_key) print("Total Keywords Used:- "+str(nn_key)) with open("keywords_.txt","+a") as kw: kw.writelines("Video URL:- "+ url+"\n") kw.writelines("Video Title:- "+"str("+str(title.encode("utf-8"))+",'utf-8')"+"\n") kw.writelines("Keywords:- "+str(key)+"\n") kw.writelines("Total No. of Keywords:- "+ str(nn_key)+"\n") kw.writelines("========================================================================="+"\n\n") count += 1