Question: python code that prints the 25 most common words found in any url of choice example of url can be w3schools. Beautifulsoup should not be
python code that prints the 25 most common words found in any url of choice example of url can be w3schools. Beautifulsoup should not be used please.
htmlParser should be extended. Here is some of my code.
from urllib.request import urlopen from html.parser import HTMLParser class link_parser(HTMLParser): # inherits and extends HTMLparser, we will override handle_starttag attribute container = "" result = {} def handle_starttag(self, tag, attrs): while tag in {"p", "h3"}: # most words were wrapped around&
tag
break def handle_data(self, data): word_count = {} self.container += data print(self.container) # i need to be able to grab only words from my url but both symbols, spaces are printing, not able to grab only texts. # also i need a way to loop through the words after collecting them so i can count the 25 most common words. but i tried to loop, it returns as letters instead of words. # for word in self.container: # if word in word_count: # word_count[word] += 1 # else: # word_count[word] = 1 # c = Counter(word_count) # top = c.most_common(25) # print(top)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
