Codecademy Logo

Beautiful Soup

Related learning

  • Can't download the data you need? Learn how to pull data right from the page by web scraping with the Python library Beautiful Soup.
    • With Certificate
    • Intermediate.
      2 hours

Beautiful Soup Object and Methods

BeautifulSoup uses a parser to take in the content of a webpage. It provides tree traversal and advanced searching methods. It creates an object from the website contents.

# This line of code creates a BeautifulSoup object from a webpage:
soup = BeautifulSoup(webpage.content, "html.parser")
# Within the `soup` object, tags can be called by name:
first_div = soup.div
# or by CSS selector:
all_elements_of_header_class = soup.select(".header")
# or by a call to `.find_all`:
all_p_elements = soup.find_all("p")

Beautiful Soup Traversal

BeautifulSoup is a Python library used to parse and traverse an HTML page. Beautiful Soup can scrape webpage data and collect it in a form suitable for data analytics.

Learn more on Codecademy

  • Can't download the data you need? Learn how to pull data right from the page by web scraping with the Python library Beautiful Soup.
    • With Certificate
    • Intermediate.
      2 hours