Scraping a table from webpage with Python
Question: 
    from bs4 import BeautifulSoup
    from urllib import urlopen
    
    player_code = open("/Users/brandondennis/Desktop/money/CF_Name.txt").read()
    player_code = player_code.split("\r")
    
    
    for player in player_code:
    
    html =urlopen("https://www.capfriendly.com/players/"+player+"")
    
    soup = BeautifulSoup(html, 'html.parser')
    
    for section in soup.findAll('div',{"class": "table_c"}):
        table = section.findChildren()[10].text
        print player, table
    

Here is a link to a sample player page :
<https://www.capfriendly.com/players/patrik-elias>

Here is a sample of player names that I am adding from a text file to the base
url.

[![enter image description
here](http://i.stack.imgur.com/CtwbE.png)](http://i.stack.imgur.com/CtwbE.png)

[![This is ultimately What I am wanting to do for my text file of 1000+
players
](http://i.stack.imgur.com/PdQQg.png)](http://i.stack.imgur.com/PdQQg.png)

This is ultimately what I am wanting to do for my text file of 1000+ players


Answer: Aside from what the others mentioned. Take a look at this line:

    
    
    table = soup.findAll('table_c')[2]
    

here, `BeautifulSoup` would try to locate `table_c` elements. But, `table_c`
is a class attribute:

    
    
    <div class="table_c"><div class="rel navc column_head3 cntrct"><div class="ofh"><div>HISTORICAL SALARY </div><div class="l cont_t mt4">SOURCE: The Hockey News, USA Today</div></div></div>
        <table class="cntrct" id="contractinsert" cellpadding="0" border="0" cellspacing="0">
        ...
        </table>
    </div>
    

Use the `class_` argument instead:

    
    
    table = soup.find_all(class_='table_c')[2] 
    

Or, you may get directly to the table by `id`:

    
    
    table = soup.find("table", id="contractinsert")
    

