Write a function that opens a web page and returns a dictionary of all thelinks and their text on that page. A link is defined by an HTML tag that looks like
< ahref="http://my.computer.com/some/file.html">link text < /a>
The link is everything in quotes after thehref=, and the text is everything between the > and the . For the example above, the entry in a dictionary would look like:
"{"http:// my.computer.com/some/file.html" : " link text ", ...}"
Here's my code so far I've been stuck on for a few hours. How do I accomplish this problem?
import urllib.request
def Urls(webpage):
url = webpage
page = urllib.request.urlopen(url)
url_list = {}
for line in page:
if '<a href=' in line: