Crate table_extract [] [src]

Utility for parsing HTML tables.

This library provides support for extracting tables from HTML documents and iterating over their rows. There are three ways of extracting tables:

  • [Table::find_first] gets the first table.
  • [Table::find_by_id] finds a table by its HTML id.
  • [Table::find_by_headers] finds a table that has certain headers.

Each of these returns an [Option<Table>], since there might not be any matching table in the HTML. Once you have a table, you can iterate over it and access the contents of each [Row].

Examples

let html = r#"
    <table>
        <tr><th>Name</th><th>Age</th></tr>
        <tr><td>John</td><td>20</td></tr>
    </table>
"#;
let table = table_extract::Table::find_first(html);
for row in &table {
    println!(
        "{} is {} years old",
        row.get("Name").unwrap_or("<name missing>"),
        row.get("Age").unwrap_or_else("<age missing>")
    )
}

Structs

Iter

An iterator over the rows in a [Table].

Row

A row in a [Table].

Table

A parsed HTML table.

Type Definitions

Headers

A map from <th> table headers to their zero-based positions.