Download the sample files from the banner, then click Add files in the workbench. open("kiosk.html") looks in /uploads.
Goal
List /uploads, parse kiosk.html and article.html, and read titles from feed.xml.
See what is attached
import os
print("uploads:", os.listdir("/uploads"))If that list is empty, attach the files and run again.
kiosk.html
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([a.get("href") for a in soup.select("nav a")])
print([li.get_text(strip=True) for li in soup.select("li.item")])Both kiosk.html and /uploads/kiosk.html work.
article.html
with open("article.html") as f:
soup = BeautifulSoup(f.read(), "html.parser")
print(soup.h1.get_text())
print([a.get("href") for a in soup.find_all("a")])feed.xml with html.parser
with open("feed.xml") as f:
soup = BeautifulSoup(f.read(), "html.parser")
print(soup.find("title").get_text())
for item in soup.find_all("item"):
print(item.find("title").get_text(), item.find("link").get_text())This editor has no lxml, so do not pass "xml". html.parser is enough for this tiny feed.
Pitfall
FileNotFoundError means the workbench cannot see the file in /uploads. Download from the banner, then Add files. Do not fetch the page from the internet.