Challenge: Find All
Tarefa
Swipe to start coding
You will work with the following page.
- Print the first
<div>
tag using the function.find()
of the objectsoup
. - Print the instances of
<p>
tags where theid
attributes are equal to"id0"
using the function.find_all()
of thesoup
object.
Solução
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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/mother.html"
page = urlopen(url)
html = page.read().decode("utf-8")
# Create the BeautifulSoup object
soup = BeautifulSoup(html, "html.parser")
# Print the first `<div>` tag
print(soup.find("div"))
# Print the tag `<p>` with the correct id
print(soup.find_all("p", {"id": "id0"}))
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 6
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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/mother.html"
page = urlopen(url)
html = page.read().decode("utf-8")
# Create the BeautifulSoup object
soup = BeautifulSoup(html, "html.parser")
# Print the first `<div>` tag
___
# Print the tag `<p>` with the correct id
___
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo