This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Creating a list of dictionaries to then convert into a Pandas Dataframe | |
| wiz_stats = [] | |
| for row in wiz_per_game.find_all('tr')[1:]: # Excluding the first 'tr', since that's the table's title head | |
| player = {} | |
| player['Name'] = row.find('a').text.strip() | |
| player['Age'] = row.find('td', {'data-stat' : 'age'}).text | |
| player['Min PG'] = row.find('td', {'data-stat' : 'mp_per_g'}).text | |
| player['Field Goal %'] = row.find('td', {'data-stat' : 'fg_pct'}).text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wiz_url = (f'https://www.basketball-reference.com/teams/WAS/2021.html') | |
| # The requests library can send a GET request to the wiz_url | |
| wiz_res = requests.get(wiz_url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Creating a list of url endings for each NBA team's webpage | |
| team_list = [] | |
| for i in select_team.find_all('option')[1:31]: | |
| name = i.get('value') | |
| team_list.append(name) | |
| team_list[0:3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| base_url = 'https://www.basketball-reference.com/' | |
| # The requests library can send a GET request to the base_url | |
| res_base = requests.get(base_url) | |
| # BeautifulSoup library parses the content of an HTML document, in this case res_base | |
| base_soup = BeautifulSoup(res_base.content, 'lxml') | |
| # BeautifulSoup's .find() method searches for a tag and specified attributes, returning the first match | |
| select_team = base_soup.find(name = 'div', attrs = {'id' : 'teams'}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import requests | |
| from bs4 import BeautifulSoup | |
| import re |
NewerOlder