// Copyright 2026 Leo Cheng
// SPDX-License-Identifier: Apache-2.0
///|
/// A page in, a table out: the shape of every scraping job.
///
/// moon run examples/scrape
#coverage.skip
fn main raise @moonxml.Refused {
let page = @html.loads(
"| item | price |
" +
"| coffee | 4.50 |
| tea | 3.00 |
| cocoa | 5.25 |
",
)
println("item,price")
for row in page.css("#prices tbody tr").items {
let cells = row.css("td")
println("\{cells.first().text()},\{cells.last().text()}")
}
let mut total = 0.0
for cell in page.css("td:last-child").items {
total = total + parse_price(cell.text())
}
println("total,\{total}")
}
///|
fn parse_price(text : String) -> Double {
@string.parse_double(text) catch {
_ => 0.0
}
}