Challenge: The BeautifulSoup Object
Завдання
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.
Рішення
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)
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 2. Розділ 3
single
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
___
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат