Get the current leader of each stat provided by http://www.espn.com/nba/statistics and print the stat title and the list of player in order.
ex:
Offensive Leaders:
POINTS PPG
1. Russell Westbrook, OKC 31.4
2. Anthony Davis, NO 28.6
3. DeMarcus Cousins, SAC 28.5
4. James Harden, HOU 27.9
5. Isaiah Thomas, BOS 27.7
-------------------------------------------------------
ASSISTS APG
1. James Harden, HOU 11.9
2. Russell Westbrook, OKC 10.3
3. John Wall, WSH 10.2
4. Chris Paul, LAC 9.6
5. LeBron James, CLE 8.4
-------------------------------------------------------
...
Suggested approach:
In [ ]:
# Todo
1. Download the HTML
2. Find stat boxes with BeautifulSoup
3. Get Stat title, and list of players from each stat
4. Print results with formatting
In [18]:
import requests
from bs4 import BeautifulSoup
html = requests.get('http://www.espn.com/nba/statistics').text
soup = BeautifulSoup(html, 'lxml')
boxes = soup.select('#my-players-table .span-2 .mod-container')
for box in boxes:
for row in box.select('table tr'):
items = row.find_all('td')
if len(items) > 2:
items = items[1:]
if len(items) > 1:
print('{:50}{}'.format(items[0].get_text(), items[1].get_text()))
print('-' * 55)
In [ ]: