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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:32:53+00:00 2026-05-25T23:32:53+00:00

I am trying to scrape a table here very similar in structure to my

  • 0

I am trying to scrape a table here very similar in structure to my previous question. I just changed the attributes names but I am getting index out of range error. This is the TR:

<TR VALIGN="bottom">
<TD BGCOLOR=#cc6600 ALIGN="center" ><FONT FACE="Verdana, Arial, Helvetica, sans-serif">1</FONT></TD>
<TD BGCOLOR=#CC6600 ALIGN="left" ><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Wachtell, Lipton</FONT></TD>
<TD BGCOLOR=#CC6600 ALIGN="center" ><FONT FACE="Verdana, Arial, Helvetica, sans-serif">1 </FONT></TD>
<TD BGCOLOR=#CC6600 ALIGN="center" ><FONT FACE="Verdana, Arial, Helvetica, sans-serif">9.1%</FONT></TD>
<TD BGCOLOR=#FF9933 ALIGN="center" ><FONT FACE="Verdana, Arial, Helvetica, sans-serif">$3,385,000 </FONT></TD>
</TR>

I am trying to get the first ALIGN="left" and the last ALIGN="center". But the index for the last line gives the error. Here is the code I am using:

    soup = BeautifulSoup(urllib.urlopen("http://www.law.com/special/professionals/amlaw/amlaw200/amlaw200_ppp.html"))
    rows = soup.findAll(name='tr',attrs={'valign':'bottom'}, limit=13)
    for row in rows:
        tds_left = row.findAll(name='td',attrs={'align':'left'}, limit=13)
        tds_center = row.findAll(name='td',attrs={'align':'center'}, limit=13)
        if tds_left:
            firm_name = tds_left[0].text
        if tds_center:
            # the following line gives an error if the index is different than 0
            ppp = tds_center[0].text

Thanks!

Update

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 701, in __call__
    handler.get(*groups)
  File "C:\U\A\D\\toplawfirms.py", line 384, in get
    ppp = tds_center[2].text
IndexError: list index out of range

Update

As response to agf‘s comment here are print tds_center and for item in tds_center: print item?

tds_center: []
tds_center: []
tds_center: []
tds_center: [ ]
item: 
tds_center: []
item: 
tds_center: [Rank By 
Profits Per 
Partner, Rank By 
Revenue 
Per Lawyer, Change In 
Profits per 
Partner
from 1998, Profits Per 
Partner]
item: Rank By 
Profits Per 
Partner
item: Rank By 
Revenue 
Per Lawyer
item: Change In 
Profits per 
Partner
from 1998
item: Profits Per 
Partner
tds_center: [1, 1 , 9.1%, $3,385,000 ]
item: 1
item: 1 
item: 9.1%
item: $3,385,000 
tds_center: [2, 2 , 5.0%, $3,055,000 ]
item: 2
item: 2 
item: 5.0%
item: $3,055,000 
tds_center: [3, 4 , 2.9%, $2,110,000 ]
item: 3
item: 4 
item: 2.9%
item: $2,110,000 
tds_center: [4, 3 , 8.7%, $1,790,000 ]
item: 4
item: 3 
item: 8.7%
item: $1,790,000 
tds_center: [5, 9 , 6.9%, $1,710,000 ]
item: 5
item: 9 
item: 6.9%
item: $1,710,000 
tds_center: [6, 6 , 10.8%, $1,655,000 ]
item: 6
item: 6 
item: 10.8%
item: $1,655,000 
tds_center: [7, 5 , 5.1%, $1,610,000 ]
item: 7
item: 5 
item: 5.1%
item: $1,610,000 
  • 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-25T23:32:53+00:00Added an answer on May 25, 2026 at 11:32 pm

    I modified how you are getting the last “center” td in the following code:

    import urllib
    from BeautifulSoup import BeautifulSoup
    soup = BeautifulSoup(urllib.urlopen("http://www.law.com/special/professionals/amlaw/amlaw200/amlaw200_ppp.html"))
    rows = soup.findAll(name='tr',attrs={'valign':'bottom'}, limit=13)
    for row in rows:
        tds_left = row.findAll(name='td',attrs={'align':'left'}, limit=13)
        tds_center = row.findAll(name='td',attrs={'align':'center'}, limit=13)
        if tds_left:
            firm_name = tds_left[0].text
            print firm_name
        if tds_center:
            # get last td "center"
            ppp = tds_center[-1].text
            print ppp
    

    and got the following result:

    Firm
    Profits PerPartner
    Wachtell, Lipton
    $3,385,000
    Robins, Kaplan
    $3,055,000
    Cravath
    $2,110,000
    Sullivan &amp; Cromwell
    $1,790,000
    Cahill Gordon
    $1,710,000
    Simpson Thacher
    $1,655,000
    Davis Polk
    $1,610,000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to scrape an ASP.NET website but am having trouble getting the
I am trying to scrape table data from a website. Here is a simple
Trying to scrape data from totalfilm.com using YQL but I'm getting a strange error:
Trying to scrape images and data from a website using Xpath but keeps showing
I am trying to scrape some data from a page with a table based
I'm having difficulties scraping dynamically generated table in ASPX. Trying to scrape the gas
I'm trying to scrape a page but the initial response has nothing in the
I'm trying to scrape thesession.org to create a table of how many times each
I am trying to scrape a table website with mechanize. I want to scrape
I am trying to scrape a row in a table with a date. I

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.