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

Using Python programming language, Implement function links() that takes as inpu

ID: 3884695 • Letter: U

Question

Using Python programming language, 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 HTML file twolinks.html or any HTML file downloaded from the web into the folder where your program is.

CALL

>>> links( 'twolinks.html ' )

>>>2

Explanation / Answer

import urllib2 // This has the inbuilt methods
import re

def getLinks(url) //Input the URL
html_page = urllib2.urlopen() // to open th URL
Picklinks= Twolinks(html_page)
links = []

for link in picklinks.findAll('a', attrs={'href': re.compile("^http://")}): // this will get all the links
links.append(link.get('href'))

return links

)

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