Challenge: Read the HTML File
Opgave
Swipe to start coding
Open and read the HTML file on your own!
- Import the
urlopen
function from theurllib.request
. - Use the
urlopen()
function to open the page from the specifiedurl
. - Read the page and decode the received bytes object to
"utf-8"
.
Løsning
# Importing the module
from urllib.request import urlopen
# Opening web page
url = "https://codefinity-content-media.s3.eu-west-1.amazonaws.com/18a4e428-1a0f-44c2-a8ad-244cd9c7985e/page.html"
page = urlopen(url)
# Reading and decoding
web_page = page.read().decode("utf-8")
print(web_page)
Var alt klart?
Tak for dine kommentarer!
Sektion 1. Kapitel 9
# Importing the module
___
# Opening web page
url = "https://codefinity-content-media.s3.eu-west-1.amazonaws.com/18a4e428-1a0f-44c2-a8ad-244cd9c7985e/page.html"
page = ___(url)
# Reading and decoding
web_page = page.___().___("___")
print(web_page)