# Is there a ready-made function to convert a Gumbo.jl parsed html table into a table like DataFrames.DataFrame?

**URL:** <https://discourse.julialang.org/t/is-there-a-ready-made-function-to-convert-a-gumbo-jl-parsed-html-table-into-a-table-like-dataframes-dataframe/55973>\
**Category:** General Usage\
**Created:** [February 25, 2021, 12:36am UTC](https://discourse.julialang.org/t/is-there-a-ready-made-function-to-convert-a-gumbo-jl-parsed-html-table-into-a-table-like-dataframes-dataframe/55973 "2021-02-25T00:36:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [February 25, 2021, 12:36am UTC](https://discourse.julialang.org/t/is-there-a-ready-made-function-to-convert-a-gumbo-jl-parsed-html-table-into-a-table-like-dataframes-dataframe/55973/1 "2021-02-25T00:36:40Z")

</div>

I tried to read through Gumbo.jl pages but I don’t see a function to convert a `table` tag to a table.

Does such functions exists or I need to roll my own?

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 1, 2021, 8:23am UTC](https://discourse.julialang.org/t/is-there-a-ready-made-function-to-convert-a-gumbo-jl-parsed-html-table-into-a-table-like-dataframes-dataframe/55973/2 "2021-03-01T08:23:04Z")

</div>

I don’t think this is implemented, there’s talk on [https://github.com/JuliaWeb/Gumbo.jl/issues/71](https://github.com/JuliaWeb/Gumbo.jl/issues/71) to support it though.

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 1, 2021, 2:30pm UTC](https://discourse.julialang.org/t/is-there-a-ready-made-function-to-convert-a-gumbo-jl-parsed-html-table-into-a-table-like-dataframes-dataframe/55973/3 "2021-03-01T14:30:45Z")

</div>

Here’s what I ended up using:

```julia
using Gumbo
using Cascadia
using StringEncodings
using DataFrames

function html2df(file; encoding=enc"UTF-8")
    if encoding isa AbstractString
        encoding = Encoding(encoding)
    end

    n = parsehtml(read(file, String, encoding))

    dfs = DataFrame[]
    for table in eachmatch(sel"table", n.root)
        # Get column names from table
        headers = eachmatch(sel"thead tr th", table) .|> nodeText

        # Create dataframe with all columns of String type
        types = fill(String, length(headers))
        df = DataFrame(types, headers)

        # Fill dataframe with rows from the table
        for row in eachmatch(sel"tbody tr", table)
            row_texts = eachmatch(sel"td", row) .|> nodeText
            push!(df, row_texts)
        end

        push!(dfs, df)
    end

    return dfs
end

```

It takes a file name and returns an array of dataframes, one for each table in the file.
