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 8837165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:39:23+00:00 2026-06-14T09:39:23+00:00

I have an HTML document, and I want to parse out a table with

  • 0

I have an HTML document, and I want to parse out a table with a specific id, which is always within a div tag with a specific id. Here is what I’ve tried:

soup = BeautifulSoup(html)
target_div = soup('div', {'id' : 'left'})
target_table = target_div.findNextSibling('table')

Clearly that’s not working. It seems that my second statement returns a ResultSet instead of moving me around the document (which I suppose makes sense, but I’m not sure how to get what I need otherwise!). What is the correct methodology for doing this kind of parsing?

  • 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-06-14T09:39:25+00:00Added an answer on June 14, 2026 at 9:39 am

    findNextSibling looks for tables that are contained in the same parent as the original target_div element. You want to look for a table contained in the div. Use .find() for that:

    target_div = soup.find('div', {'id' : 'left'})
    target_table = target_div.find('table')
    

    and for simple cases (such as the contained table) you can use the tagname as an attribute:

    target_div = soup.find('div', {'id' : 'left'})
    target_table = target_div.table
    

    You were calling a tag, which is like using the .find_all() method. .find_all() returns all matching tags, a list. You’d have to loop over the result set, but since you are looking for a single div (using its id) you are better off using .find() which returns just one result.

    If you do need to process more than one match, just treat the result of .find_all() as a list; loop over it:

    for element in soup.find_all('div')
        contained_table = element.find('table')
    

    or use indices:

    second_match = soup.find_all('div')[1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML document that I want to remove specific tags from, identified
I have HTML code from which I want to parse values for hyperlinks, and
I have a html document and I want to delete all the divs of
I have an HTML document as a string I want to search for a
I have a document file containing HTML markup. I want to assign the contents
Possible Duplicate: How to parse and process HTML with PHP? I have HTML document
I have a HTML document with the below setup: <div class=main-div style=padding: 5px; border:
I have an html document with multiple commented-out PHP arrays, e.g.: <!-- Array (
I'm having trouble selecting links in my html. Here's the html I have: <div
I have to parse an HTML document into different new files. The problem is

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.