title: Get table with maximum number of rows in a page using BeautifulSoup
body: <p>Can anyone tell me how i can get the table in a HTML page which has a the most rows? I'm using BeautifulSoup.</p>
  
  <p>There is one little problem though. Sometimes, there seems to be one table nested inside another. </p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>When the <code>table.findAll('tr')</code> code executes, it would count all the child rows for the table and the rows for the nested table under it. The parent table has just one row but the nested table has three and I would consider that to be the largest table. Below is the code that I'm using to dig out the largest table currently but it doesn't take the aforementioned scenario into consideration. </p>
  
  <pre><code>soup = BeautifulSoup(html)
  
  #Get the largest table
  largest_table = None
  max_rows = 0
  for table in soup.findAll('table'):
      number_of_rows = len(table.findAll('tr'))
      if number_of_rows &gt; max_rows:
          largest_table = table
          max_rows = number_of_rows
  </code></pre>
  
  <p>I'm really lost with this. Any help guys?</p>
  
  <p>Thanks in advance</p>