beautifulsoup import python code example

Example 1: beautifulsoup4 install

pip install beautifulsoup4

Example 2: import beautifulsoup

from requests import get
from bs4 import BeautifulSoup as bs

page = get("http://website.url/goes-here")
soup = bs(page.content, 'html.parser')

Example 3: use beautifulsoup

#start


from bs4 import BeautifulSoup
import requests

req = requests.get('https://www.slickcharts.com/sp500')
soup = BeautifulSoup(req.text, 'html.parser')

Example 4: python import beautifulsoup

from bs4 import BeautifulSoup
import requests