HTML parsing library for Corros.
A BeautifulSoup-style HTML parser for Corros — parse any HTML into a node
tree, then query it with find, find_all, CSS-ish selectors, and text
extraction. Written entirely in Corros,
the from-scratch scripting language. No Python, no dependencies.
| Python package | brothforge |
|---|---|
soup = BeautifulSoup(html, "html.parser") |
page = broth_parse(html) |
soup.find("h1") |
broth_find(page, "h1") |
soup.find_all("p") |
broth_find_all(page, "p") |
soup.select("p.note") |
broth_select(page, "p.note") |
soup.get_text() |
broth_text(page) |
tag["href"] |
broth_attr(tag, "href") |
tag.text |
broth_text(tag) |
tag.children |
broth_children(tag) |
soup.title.string |
broth_title(page) |
curl -fsSL https://raw.githubusercontent.com/CocoCopi/brothforge/main/install.sh | sh
brothforge https://example.comadopt "/path/to/brothforge/src/broth.cro"
forge page = broth_parse(html) // root node
forge h1 = broth_find(page, "h1") // first <h1>
forge ps = broth_find_all(page, "p") // every <p>
forge note = broth_select(page, "p.note") // CSS-ish selectors
forge links = broth_select(page, "a[href]") // (attribute selectors not supported yet — use broth_links)
speak(broth_text(h1)) // "Hello", entities decoded
speak(broth_attr(broth_find(page, "img"), "src")) // "x.png"
speak(broth_pretty(page)) // indented tree
tag, .class, #id, tag.class, tag#id, descendant ("ul li"),
child ("div > p"), and comma groups ("h1, footer").
- comments (
<!-- -->), doctypes, processing instructions - self-closing tags (
<img src="x.png">without</img>) - void elements (br, img, input, meta, link, hr, …)
- implied closing:
<li>A<li>B→ two<li>, block tags close<p> - single-quoted, double-quoted, and unquoted attribute values
- uppercase tags/attrs normalized to lowercase
- HTML entities in text (
&,<,>,",', )
adopt "/path/to/brothforge/src/broth.cro"
adopt "/path/to/courierforge/src/courier.cro"
forge r = courier_get("https://example.com", nil)
forge page = broth_parse(r["body"])
speak(broth_title(page)) // "Example Domain"
each a in broth_links(page) {
speak(a["text"] + " -> " + str(a["href"]))
}
corros tests/t_broth.croCovers structure, selectors, entities, implied closing, void elements, serialization round-trips, and pretty printing.
MIT — see LICENSE. Built with Corros; see the Corros repo for the language.
