hacking sorcerer
가장 많은 걸 골라보세요
hacking sorcerer
2023. 5. 12. 13:58
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
반응형