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

  • Home
  • SEARCH
  • 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 6591775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:28:08+00:00 2026-05-25T17:28:08+00:00

I am trying to parse a table with two columns and insert the text

  • 0

I am trying to parse a table with two columns and insert the text from each column into two lists.

I need some ideas how to do it.

from BeautifulSoup import BeautifulSoup

s = """<table><tr><td valign="top" width="25%"><b>Text1</b><a href="#">Link1</a>:</b></td><td>AAAA<a href="#">BBBB</a></td></tr>
<tr><td valign="top" width="25%"><b>Text2:</b></td><td>CCCC<a href="#">DDDD</a></td></tr>
<tr><td valign="top" width="25%"><b><a href="#">Link2</a>:</b></td><td><a href="#">EEEE</a> FFFF</td></tr></table>
<tr><td valign="top" width="25%"><b>Text3 <br> Text4:</b></td><td><a href="#">EEEE</a> FFFF</td></tr></table>"""

a = BeautifulSoup(s)

b = a.findAll('td', text=True)

left = []
right = []

for i in b:
    print i

What I get:

Text1
Link1
:
AAAA
BBBB

What I need:

left = [“Text1”, “Link1”]
right = [AAAA”, “BBBB”]

  • 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-25T17:28:09+00:00Added an answer on May 25, 2026 at 5:28 pm

    Get the row first, and then get the cell:

    left = []
    right = []
    
    for tr in a.findAll('tr'):
        l, r = tr.findAll('td')
        left.extend(l.findAll(text=True))
        right.extend(r.findAll(text=True))
    

    I haven’t tested this, but pretty sure it should work 🙂

    EDIT: fixed (hopefully)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse a html page and extract 2 values from a table
Trying to parse an HTML document and extract some elements (any links to text
ok so I am trying to parse XML data into a table, this is
I am trying to parse a table in the form of a text file
While trying to parse an xml file into table format, jQuery keeps closing my
I'm trying to parse a text file word by word and I need to
I'm trying to parse an entire MySQL table into files named after the rows.
I am trying to parse the table shown here into a multi-dimensional php array.
I've got an HTML table that I'm trying to parse the information from. However,
Trying to parse Maplines for an airport. Each airport can have X number of

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.