<jupyter_start><jupyter_text>Injuries<jupyter_code># URL page we will scraping (see image above)
url = "https://www.basketball-reference.com/friv/injuries.fcgi"
# this is the HTML from the given URL
html = urlopen(url)
soup = BeautifulSoup(html)
headers = [th.getText() for th in soup.findAll('tr')[0].findAll('th')]
headers
players = []
for tr in soup.findAll('tr')[1:]:
    players.append(tr.findAll('th')[0].getText())
players
rows = soup.findAll('tr')[1:]
inj = [[td.getText() for td in rows[i].findAll('td')] for i in range(len(rows))]
inj
for i in range(len(inj)):
    inj[i].insert(0,players[i])
inj
injuries = pd.DataFrame(inj, columns = headers)
injuries<jupyter_output><empty_output><jupyter_text>Today's games<jupyter_code>import json
with urlopen("https://cdn.nba.com/static/json/liveData/scoreboard/todaysScoreboard_00.json") as url:
    data = json.loads(url.read().decode())
    print(data['scoreboard']['games'])
games = []
for game in data['scoreboard']['games']:
    # home = game['homeTeam']['teamCity'] + " " + game['homeTeam']['teamName']
    # away = game['awayTeam']['teamCity'] + " " + game['awayTeam']['teamName']
    # games.append([home, away])
    games.append([game['homeTeam']['teamTricode'], game['awayTeam']['teamTricode']])
today_games = pd.DataFrame(games, columns=['Home', 'Away'])
today_games<jupyter_output><empty_output><jupyter_text>NBA Team Abbreviations<jupyter_code>espn_mapping = {'Atlanta Hawks':'ATL', 'Brooklyn Nets':'BKN', 'Boston Celtics':'BOS', 'Charlotte Hornets':'CHA',
        'Chicago Bulls':'CHI', 'Cleveland Cavaliers':'CLE', 'Dallas Mavericks':'DAL', 'Denver Nuggets':'DEN',
        'Detroit Pistons':'DET', 'Golden State Warriors':'GSW', 'Houston Rockets':'HOU', 'Indiana Pacers':'IND',
        'Los Angeles Clippers':'LAC', 'Los Angeles Lakers':'LAL', 'Memphis Grizzlies':'MEM', 'Miami Heat':'MIA',
        'Milwaukee Bucks':'MIL', 'Minnesota Timberwolves':'MIN', 'New Orleans Pelicans':'NO',
        'New York Knicks':'NYK', 'Oklahoma City Thunder':'OKC', 'Orlando Magic':'ORL', 'Philadelphia 76ers':'PHI',
        'Phoenix Suns':'PHX', 'Portland Trailblazers':'POR', 'Sacramento Kings':'SAC', 'San Antonio Spurs':'SAS',
        'Toronto Raptors':'TOR', 'Utah Jazz':'UTAH', 'Washington Wizards':'WSH'}
full = list(espn_mapping.keys())
abbr = list(espn_mapping.values())
print(full)
print(abbr)<jupyter_output>['Atlanta Hawks', 'Brooklyn Nets', 'Boston Celtics', 'Charlotte Hornets', 'Chicago Bulls', 'Cleveland Cavaliers', 'Dallas Mavericks', 'Denver Nuggets', 'Detroit Pistons', 'Golden State Warriors', 'Houston Rockets', 'Indiana Pacers', 'Los Angeles Clippers', 'Los Angeles Lakers', 'Memphis Grizzlies', 'Miami Heat', 'Milwaukee Bucks', 'Minnesota Timberwolves', 'New Orleans Pelicans', 'New York Knicks', 'Oklahoma City Thunder', 'Orlando Magic', 'Philadelphia 76ers', 'Phoenix Suns', 'Portland Trailblazers', 'Sacramento Kings', 'San Antonio Spurs', 'Toronto Raptors', 'Utah Jazz', 'Washington Wizards']
['ATL', 'BKN', 'BOS', 'CHA', 'CHI', 'CLE', 'DAL', 'DEN', 'DET', 'GSW', 'HOU', 'IND', 'LAC', 'LAL', 'MEM', 'MIA', 'MIL', 'MIN', 'NO', 'NYK', 'OKC', 'ORL', 'PHI', 'PHX', 'POR', 'SAC', 'SAS', 'TOR', 'UTAH', 'WSH']<jupyter_text>Remaining Games<jupyter_code>url = "https://www.basketball-reference.com/teams/GSW/2021_games.html"
# this is the HTML from the given URL
html = urlopen(url)
soup = BeautifulSoup(html)
headers = ['Date','Start (ET)','','Box Score','Home/Away','Opponent','W/L','OT','Score','Opp','W','L','Streak','Notes']
rows = soup.findAll('tr')[1:]
gms = [[td.getText() for td in rows[i].findAll('td')] for i in range(len(rows))]
gms
games = pd.DataFrame(gms, columns = headers)
future_games = games[(games['W/L'] == '')]
future_games = future_games.reset_index()
future_games = future_games.drop(columns=['index','','Box Score','W/L','OT','Score','Opp','W','L','Streak','Notes'])
future_games['Opponent'] = future_games['Opponent'].map(espn_mapping)
future_games<jupyter_output><empty_output><jupyter_text>Depth Charts<jupyter_code>depth_charts = {}
for d in abbr:
    url = "https://www.espn.com/nba/team/depth/_/name/" + d
    html = urlopen(url)
    soup = BeautifulSoup(html)
    rows = soup.findAll('tr')
    depth = []
    for r in rows[7:]:
        position = []
        for a in r.findAll('a'):
            position.append(a.getText())
        depth.append(position)
    list(map(list, zip(*depth)))
    depth_charts[d] = depth
    sleep(1)
print(depth_charts)<jupyter_output>{'ATL': [['<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>'], ['<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>'], ["<NAME>", '<NAME>', '<NAME>', '<NAME>', '<NAME>'], ['<NAME>', '<NAME>', '<NAME>', '<NAME>', "De'<NAME>"], ['<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>']], 'BKN': [['<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>'], ['<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>'], ['<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>'], ['<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>'], ['<NAME>', '<NAME>', 'De<NAME>', '<NAME>', '<NAME>']], 'BOS': [['<NAME>', '<NAME>', '<NAME>', 'Tremont Waters', '<NAME>'], ['<NAME>', 'Evan Four[...]
{'fraction_non_alphanumeric': 0.24123064863805604, 'fraction_numerical': 0.003527336860670194, 'mean_word_length': 6.365079365079365, 'pattern_counts': {'":': 0, '<': 74, '<?xml version=': 0, '>': 74, 'https://': 4, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '171894', 'license': 'Unlicense', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1852, 'n_words': 399, 'path': 'Project/NBA Scraping Testing.ipynb', 'repo_name': 'PeterXiao-create/DraftKings_prediction_ML', 'size': '5470'}