Read HTML files into Deephaven tables

Deephaven does not provide built-in methods for reading HTML tables in Groovy. Because Groovy runs on the JVM, you can use any Java HTML parsing library to pull data from HTML into Deephaven tables.

jsoup is a popular Java library for parsing HTML, similar to BeautifulSoup in Python. It parses malformed HTML, and it can both download and parse a web page.

Deephaven doesn't include jsoup, so add it to the classpath before you use it. See Install and use Java packages for instructions on how to add external JARs to a Deephaven worker.

Read an HTML table with jsoup

Let's start with an example that reads a small HTML table of stock trades from a string. Jsoup.parse parses the HTML, select finds the header cells and the body rows with CSS selectors, and text returns each cell's text. The example then builds a Deephaven table with newTable and one stringCol per header cell:

To read a table from a local HTML file instead, replace Jsoup.parse(tradesHtml) with Jsoup.parse(new File("/path/to/file.html"), "UTF-8"). To read a table from a web page, use Jsoup.connect: Jsoup.connect(url).get() downloads and parses the page.

Data types

HTML tables store all data as plain text and have no concept of data types, so every column in the trades table above is a String column. Set the correct type for each column with the update method or another of Deephaven's selection methods. This example uses Java's Double.parseDouble and Integer.parseInt methods and the built-in parseInstant function: