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

This program will be ran through a Python 3 IDE, please use correct formatting a

ID: 3681148 • Letter: T

Question

This program will be ran through a Python 3 IDE, please use correct formatting as such.

Implement function links() that takes as input the name of an HTML file (as a string) and returns the number of hyperlinks in that file. To do this you will assume that each hyperlink appears in an anchor tag. You also need to know that every anchor tag ends with the substring </a>.

Test your code on any HTML file downloaded from the web into the folder where your program is.

Here is an example of how the program should look.

>>> links('twolinks.html')

2

Explanation / Answer

import re

bible = open("sourceHtml.html", "r")
regex = re.compile(r'</a>')
count=0;
for line in bible:
    four_letter_words = regex.findall(line)
    for word in four_letter_words:
        count=count+1
print "Total links are"
print count

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