You'd probably have to use recursion. That can be very tricky.
The idea is that you write a function to parse the html.
When you find a table, read all that is in that table, and pass it back to the function itself, so a new thread of the function now starts reading
just the outer-most table.
Now when it finds a new table in the outer most table, it will call itself again, working with the second outer-most table.
Just amke sure to have a failsafe mechanism to stop the whole thing after x recursions, or you could get an infinite loop if you make a typo somewhere.