Automatically Determine The Number Of Columns In An HTML Table With Python's Beautiful Soup

This is what I use to find the number of columns in an HTML table.


I'm working on an ascii art tool. It includes a full set of unicode characters to choose from. I pulled the characters from the W3C site. There are 28 pages with tables that sort everything from the top down then column by column. Something like this:

They're set up that way based of their unicode ID numbers. Makes sense on the W3C pages, but I want them sorted continuously from left to right.

I'm parsing the source HTML in Beautiful Soup then doing the formatting conversion in Pandas. I want to know the number of columns in the tables to setup the Pandas data frame explicitly. So, I setup the code snippet to figure that out. It loops through every row of the table and counts the number of `th`` (header) and `td`` (data) cells on each row then runs them through max functions to come up with the longest row.