Jul-11-2020, 08:14 PM
Fairly new to Python, so I need help with the following:
I am getting a syntax error for parser = MyHTMLParser() and I can't figure out why?
#
# Example file for parsing and processing HTML
#
from html.parser import HTMLParser
class MyHTMLparser(HTMLParser):
def handle_comment(self, data):
print("Encountered comment: ", data)
pos = self.getpos()
print ("\tAt Line: ", pos[0], " position ", pos[1]
# instantiate the parser and feed it some HTML
parser = MyHTMLParser()
f = open("samplehtml.html")
if f.mode == 'r'
contents = f.read()
parser.feed(contents)
def main():
if __name__ == "__main__":
main();
I am getting a syntax error for parser = MyHTMLParser() and I can't figure out why?
#
# Example file for parsing and processing HTML
#
from html.parser import HTMLParser
class MyHTMLparser(HTMLParser):
def handle_comment(self, data):
print("Encountered comment: ", data)
pos = self.getpos()
print ("\tAt Line: ", pos[0], " position ", pos[1]
# instantiate the parser and feed it some HTML
parser = MyHTMLParser()
f = open("samplehtml.html")
if f.mode == 'r'
contents = f.read()
parser.feed(contents)
def main():
if __name__ == "__main__":
main();