Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[Python] Please help me !!!!!!! with this coding problem. I will copy the templa

ID: 3776141 • Letter: #

Question

[Python]

Please help me !!!!!!! with this coding problem.

I will copy the template for you in the bottom. Please make sure your code works in .py file.

3.Copy below to your py file. This is exact same thing as above pictures.

---------------------------------------------------------------------------------------------

from random import randint
from tkinter import *
from tkinter.messagebox import showinfo
from urllib.request import urlopen
from urllib.parse import urljoin
from html.parser import HTMLParser
from copy import copy

# Coding problem 3: Complete the ExamParser class so that
# when its print_links method is called,
# it prints the data portion of all of the
# anchor elements found on a Web page (not the URL of
# the links). For example,
# >>> ExamParser().print_links('finalpage.html')
# CSC 242
# MAT 140

class ExamParser(HTMLParser):
     # the self.anchor variable should be used to indicate
     # that an anchor start tag has been found.
     def __init__(self):
          self.anchor = False
          HTMLParser.__init__(self)
          self.print_links('final.html')

     # write this method        
     def handle_starttag(self, tag, attrs):
          pass

     # write this method        
     def handle_data(self, data):
          pass
      
     # write this method
     def print_links(self, url):
          pass

-----------------------------------------------------------------------------------------------------------------

4.

If you open the 'finalpage.html', it looks like this:

from random import rand int from tkinter import from tkinter messagebox import show info from ur l lib. request import urlopen from url import ur l join llib.parse from html parser import HTMLParser from copy import copy

Explanation / Answer

If all the tkinter urllib are there in the path remove the comments below and execute the code.Otherwise execute the same code below

#from random import randint
#from tkinter import *
#from tkinter.messagebox import showinfo
#from urllib.request import urlopen
#from urllib.parse import urljoin
#from html.Parser import HTMLParser
#from copy import copy

from HTMLParser import HTMLParser
class ExamParser(HTMLParser):
# the self.anchor variable should be used to indicate
# that an anchor start tag has been found.
def __init__(self):
self.anchor = False
HTMLParser.__init__(self)
self.print_links('final.html')


def handle_starttag(self, tag, attrs):
print "Encountered a start tag:", tag

def handle_data(self, data):
print "Encountered some data :", data

def print_links(self, url):
print"Encountered a link :",url

parser = ExamParser()
parser.feed('<html><head><title>Test</title></head>'
'<body><h1>Parse me!</h1></body></html>')

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote