Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 864067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:24:54+00:00 2026-05-15T09:24:54+00:00

Can anyone tell me how i can get the table in a HTML page

  • 0

Can anyone tell me how i can get the table in a HTML page which has a the most rows? I’m using BeautifulSoup.

There is one little problem though. Sometimes, there seems to be one table nested inside another.

<table>
    <tr>
        <td>
            <table>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </table>
        <td>
    </tr>
</table>

When the table.findAll('tr') 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.

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 > max_rows:
        largest_table = table
        max_rows = number_of_rows

I’m really lost with this. Any help guys?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:24:54+00:00Added an answer on May 15, 2026 at 9:24 am

    Calculate number_of_rows like that:

    number_of_rows = len(table.findAll(lambda tag: tag.name == 'tr' and tag.findParent('table') == table))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me how to get remote Sqlserver instances using c# and SMO
Can anyone tell me how to get and display the biggest values from a
can anyone tell me (code sample woudl be awesome) how to get the the
Frankly, I'm flummoxed. Can anyone tell me why I would get a failure message
can any one please tell me how to get the Google places api key
Any one please tell me how can i get an event after completion of
Can anyone tell me I get the error: Fatal error: Call to a member
I am working with Microsoft visual studio 2005.Can anyone tell me how to get
Can anyone tell me the exact syntax to get rid of a comma at
can anyone tell me why this code don't work: $q = $_GET['q']; // Load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.