Attach all four sample files (kiosk.html, article.html, messy.html, feed.xml) with Add files. Paste each block as the whole editor — later blocks repeat the load so they still run alone.
Goal
Pull nav links, the sales table, and the order form from kiosk.html, then export a CSV.
1. Load
import os
print("uploads:", os.listdir("/uploads"))
with open("kiosk.html") as f:
soup = BeautifulSoup(f.read(), "html.parser")
print(soup.title.get_text())
print(soup.find("meta", attrs={"name": "city"}).get("content"))2. Nav links
with open("kiosk.html") as f:
soup = BeautifulSoup(f.read(), "html.parser")
for a in soup.select("nav a"):
print(a.get_text(strip=True), a.get("href"))3. Product list
with open("kiosk.html") as f:
soup = BeautifulSoup(f.read(), "html.parser")
for li in soup.select("li.item"):
print(li.get("data-sku"), li.get_text(strip=True), li.get("class"))4. Sales table → DataFrame
with open("kiosk.html") as f:
soup = BeautifulSoup(f.read(), "html.parser")
header = [th.get_text(strip=True) for th in soup.select("#sales thead th")]
rows = [
[td.get_text(strip=True) for td in tr.find_all("td")]
for tr in soup.select("#sales tbody tr")
]
df = pd.DataFrame(rows, columns=header)
df["units"] = pd.to_numeric(df["units"])
df["price"] = pd.to_numeric(df["price"])
print(df)
print("units sum", int(df["units"].sum()))5. Form fields
with open("kiosk.html") as f:
soup = BeautifulSoup(f.read(), "html.parser")
form = soup.find("form", id="order")
print("action", form.get("action"))
for inp in form.find_all("input"):
print(inp.get("name"), inp.get("value"))6. Export
import os
with open("kiosk.html") as f:
soup = BeautifulSoup(f.read(), "html.parser")
header = [th.get_text(strip=True) for th in soup.select("#sales thead th")]
rows = [
[td.get_text(strip=True) for td in tr.find_all("td")]
for tr in soup.select("#sales tbody tr")
]
df = pd.DataFrame(rows, columns=header)
df.to_csv("kiosk_sales.csv", index=False)
links = pd.DataFrame(
[
{"text": a.get_text(strip=True), "href": a.get("href")}
for a in soup.select("nav a")
]
)
links.to_csv("kiosk_nav.csv", index=False)
print("uploads:", os.listdir("/uploads"))
print(df)
print(links)Click ↓ on kiosk_sales.csv and kiosk_nav.csv.
Extra drills
- Pretty-print
messy.html. - List every
<item><title>infeed.xml. decomposethe sold-out<li>onkiosk.htmland writekiosk_clean.html.
You should see
If a file is missing, attach the banner files and run again. A bare soup prints nothing — wrap it in print.