Challenge: The BeautifulSoup Object
Taak
Swipe to start coding
Print the first h1
of the page tag using BeautifulSoup
:
- Import the
BeautifulSoup
frombs4
. - Create the
BeautifulSoup
object and assign it to the variablesoup
. - Access the first
<h1>
tag using thesoup
variable and print its content.
Oplossing
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Import libraries
from bs4 import BeautifulSoup
from urllib.request import urlopen
# Open the page
url = "https://codefinity-content-media.s3.eu-west-1.amazonaws.com/18a4e428-1a0f-44c2-a8ad-244cd9c7985e/jesus.html"
page = urlopen(url)
html = page.read().decode("utf-8")
# Create the BeautifulSoup object
soup = BeautifulSoup(html, "html.parser")
# Print the first h1 tag
print(soup.h1)
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 2. Hoofdstuk 3
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Import libraries
from ___ import ___
from urllib.request import urlopen
# Open the page
url = "https://codefinity-content-media.s3.eu-west-1.amazonaws.com/18a4e428-1a0f-44c2-a8ad-244cd9c7985e/jesus.html"
page = urlopen(url)
html = page.read().decode("utf-8")
# Create the BeautifulSoup object
soup = ___(___, "___")
# Print the first h1 tag
___
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.