Learn Before
Code

Creating the "soup"

To get started, we need to import BeautifulSoup from bs4, then parse our file by passing it into the BeautifulSoup constructor.

from bs4 import BeautifulSoup with open('filename.html') as f: soup = BeautifulSoup(f, 'html.parser')

A "soup" object can also be created by getting HTML content directly from a website using the Requests module:

import requests response = requests.get("https://example.com") soup = BeautifulSoup(response.content, "html.parser")

0

1

Updated 2021-05-18

Tags

Python Programming Language

Data Science