# Write a function that finds all phone numbers from # http://www.virginia.edu/contact # The function then returns a list of all phone numbers # in the area code 434. # If the same phone number appears multiple times, # only one should be reported. # For practice purposes, you should create 2 versions of your solutions. # One version reads a file from the internet; # one version reads a file from your computer (locally). import re import urllib.request def findPhoneNumber(url): phone_list = [] # Define regular expression patter that describes # phone number in area code 434. # Create a regular expression object. regex = re.compile(r'(\(434\) [0-9]{3}-[0-9]{4})') stream = urllib.request.urlopen(url).read().decode('UTF-8') matches = regex.finditer(stream) for match in matches: if match.group() not in phone_list: phone_list.append(match.group()) return phone_list url = "http://www.virginia.edu/contact" print(findPhoneNumber(url)) ########################## # Challenging: (not be in Fall 2018 final exam) # Write another function to extract the urls from the hyperlinks # for example, # a url to African-American Affairs, Office of # is http://oaaa.virginia.edu/ # a url to Financial Aid is # http://sfs.virginia.edu/ # and store them in a list of links ########################## # Even more challenging: (not be in Fall 2018 final exam) # Modify your findHyperlink(url) function such that # the urls and link texts are stored in # a dictionary, where url is a key # and the associated link text is a value