Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Find All | Working with Element Attributes in Beautiful Soup
Web Scraping with Python

book
Challenge: Find All

Tehtävä

Swipe to start coding

You will work with the following page.

  1. Print the first <div> tag using the function .find() of the object soup.
  2. Print the instances of <p> tags where the id attributes are equal to "id0" using the function .find_all() of the soup object.

Ratkaisu

# 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"}))

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 6
# 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
___
toggle bottom row
some-alt