728x90
import requests
from bs4 import BeautifulSoup
from collections import Counter
# Function to retrieve website content
def get_website_content(url):
response = requests.get(url)
return response.text
# Function to extract words from website content
def extract_words(content):
soup = BeautifulSoup(content, 'html.parser')
text = soup.get_text()
words = text.split()
return words
# Function to generate a list of most frequent words
def get_most_frequent_words(words, num_words):
word_counts = Counter(words)
most_common = word_counts.most_common(num_words)
return most_common
# Main function
def main():
url = "https://www.example.com" # Replace with the target website URL
num_words = 10 # Number of most frequent words to display
content = get_website_content(url)
words = extract_words(content)
most_frequent = get_most_frequent_words(words, num_words)
print("Most frequent words:")
for word, count in most_frequent:
print(f"{word}: {count}")
# Execute the main function
if __name__ == "__main__":
main()
728x90
'호그와트' 카테고리의 다른 글
Tryhackme에서 GURU 단계에 도달했다 (0) | 2023.05.17 |
---|---|
화가를 1초만에 끔살하는 방법 뀨~ (0) | 2023.05.14 |
Enumeration Understanding (0) | 2023.05.03 |
티키타카의 진수 (0) | 2023.05.03 |
쟤~~쟈자밌는 해킹 (0) | 2023.04.27 |