The Beautiful Soup workbench

Pyodide, html.parser, files, print, and privacy.

The Beautiful Soup app is a Python editor that runs in WebAssembly (Pyodide). When the status line says Beautiful Soup is ready, these names already exist:

  • BeautifulSoup — from bs4
  • pd — pandas
  • np — NumPy

You do not write from bs4 import BeautifulSoup unless you want to.

Goal

Know how Run, print, files, and Reset work, and why this tab never fetches the web.

Run code

Paste into the editor and press Ctrl+Enter (Windows/Linux) or Cmd+Enter (macOS). The console is stdout.

from bs4 import BeautifulSoup

html = "<p>Nairobi</p>"
soup = BeautifulSoup(html, "html.parser")
print(soup.p.get_text())

Always "html.parser"

html = "<h1>Kisumu kiosk</h1>"
soup = BeautifulSoup(html, "html.parser")
print(soup.h1)
print(type(soup.h1))

This editor does not ship lxml. html.parser is the Python standard-library parser and is enough for every chapter.

Files live in /uploads

Click Add files and choose an HTML file. After that:

import os

print(os.listdir("/uploads"))

Readable paths: kiosk.html or /uploads/kiosk.html.

with open("kiosk.html") as f:
    soup = BeautifulSoup(f.read(), "html.parser")
print(soup.title.get_text())

Privacy

Python runs in this tab. Uploads live in IndexedDB on this device. Lesson pages are public HTML; they never see your files.

Pitfall

Do not call requests.get("https://…") or urllib.request.urlopen. There is no outbound HTTP for scraping. Paste HTML as a string, or attach a banner file.