Need help with a python script that can complete the following, thanks for your
ID: 3768410 • Letter: N
Question
Need help with a python script that can complete the following, thanks for your time taken
Implement function getContent() that takes as input a URL (as a string) and prints only the text data content of the associated web page (i.e., no tags). Avoid printing blank lines that follow a blank line and strip the whitespace in every line printed.
>>> getContent('http://www.nytimes.com/')
The New York Times - Breaking News, World News & Multimedia Subscribe to The Times
Log In
Register Now
Home Page ...
Explanation / Answer
from HTMLParser import HTMLParser class MLStripper(HTMLParser): def __init__(self): self.reset() self.fed = [] def handle_data(self, d): self.fed.append(d) def get_data(self): return ''.join(self.fed) def strip_tags(html): s = MLStripper() s.feed(html) return s.get_data()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.