Building a Keyword Generator

Photo by NisonCo PR and SEO on Unsplash

Prerequisites

pip install requests beautifulsoup4 nltk

Building the keyword analysis tool

import requests
from bs4 import BeautifulSoup
import nltk
nltk.download('punkt')
from nltk.tokenize import word_tokenize
# Make a request to the website to retrieve the HTML source code
response = requests.get("https://www.example.com")
html = response.content
# Use BeautifulSoup to parse the HTML source code
soup = BeautifulSoup(html, "html.parser")
# Extract the text from the page
text = soup.get_text()
# Use the word_tokenize method from the NLTK library to tokenize the text into words
tokens = word_tokenize(text)
# Use the nltk.FreqDist method to calculate the frequency of each word in the text
freq_dist = nltk.FreqDist(tokens)
# Print the most common keywords on the page
print("Most common keywords on the page:")
for word, frequency in freq_dist.most_common(20):
print(f"{word}: {frequency}")

Conclusion

Adblock test (Why?)