Skip to content

Instantly share code, notes, and snippets.

View gabecano4308's full-sized avatar

Gabe Cano gabecano4308

  • Deloitte
  • Philadelphia
View GitHub Profile
# 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
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)
# 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]
@gabecano4308
gabecano4308 / bball ref -- requests
Last active December 29, 2020 23:08
for part two
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'})
@gabecano4308
gabecano4308 / bball ref -- imports
Last active December 29, 2020 23:33
for part 1
import pandas as pd
import requests
from bs4 import BeautifulSoup
import re