Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: The BeautifulSoup Object | Decoding HTML with Beautiful Soup
Web Scraping with Python

book
Challenge: The BeautifulSoup Object

Taak

Swipe to start coding

Print the first h1 of the page tag using BeautifulSoup:

  1. Import the BeautifulSoup from bs4.
  2. Create the BeautifulSoup object and assign it to the variable soup.
  3. Access the first <h1> tag using the soup variable and print its content.

Oplossing

# 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?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 3
# 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

expand
ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

some-alt