import csv
import requests
from bs4 import BeautifulSoup

#opening csv
outfile = open("./D-League.csv", "w")
writer = csv.writer(outfile)
writer.writerow(["Player", "Split", "Team", "GP", "GS", "Min", "FGM", "FGA", "FG%", "3PM", "3PA", 
	"3P%", "FTM", "FTA", "FT%", "ORB", "DRB", "TRB", "AST", "STL", "BLK", "PF", "TOV", "PTS"])

list_of_urls = ["https://basketball.realgm.com/player/Semaj-Christon/D-League/26729/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Luke-Babbitt/D-League/2185/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Miles-Plumlee/D-League/3654/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Shane-Larkin/D-League/28945/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Abdel-Nader/D-League/31320/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Guerschon-Yabusele/D-League/29646/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Marcus-Morris/D-League/4078/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Quincy-Acy/D-League/4130/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Joe-Harris/D-League/23549/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Sean-Kilpatrick/D-League/4347/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Jeremy-Lin/D-League/10168/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Treveon-Graham/D-League/31269/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Jeremy-Lamb/D-League/22394/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Johnny-OBryant/D-League/24170/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Julyan-Stone/D-League/8270/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Justin-Holiday/D-League/6968/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/David-Nwaba/D-League/58185/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Yogi-Ferrell/D-League/24263/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Salah-Mejri/D-League/24116/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Dwight-Powell/D-League/9346/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Seth-Curry/D-League/4873/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Josh-McRoberts/D-League/6/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Will-Barton/D-League/9269/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Malik-Beasley/D-League/73131/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Juancho-Hernangomez/D-League/52816/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Reggie-Bullock/D-League/7120/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Henry-Ellenson/D-League/54842/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Langston-Galloway/D-League/22568/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Reggie-Jackson/D-League/3771/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Stanley-Johnson/D-League/26756/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Jon-Leuer/D-League/4000/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Boban-Marjanovic/D-League/2413/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Ish-Smith/D-League/3665/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Eric-Moreland/D-League/23255/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Tarik-Black/D-League/9359/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Damien-Wilkins/D-League/295/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Willie-Reed/D-League/10776/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Jordan-Clarkson/D-League/22892/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Tyler-Ennis/D-League/27049/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Ivica-Zubac/D-League/49290/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/James-Ennis/D-League/31122/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/James-Johnson/D-League/1604/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Tyler-Johnson/D-League/23365/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Josh-Richardson/D-League/28787/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Okaro-White/D-League/9344/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Hassan-Whiteside/D-League/7693/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/AJ-Hammons/D-League/24294/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Rodney-McGruder/D-League/4210/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/DeAndre-Liggins/D-League/5713/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Cole-Aldrich/D-League/2159/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Tyus-Jones/D-League/26752/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Shabazz-Muhammad/D-League/24245/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Jordan-Crawford/D-League/4441/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Cheick-Diallo/D-League/49975/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Darius-Miller/D-League/2364/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Alexis-Ajinca/D-League/775/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Solomon-Hill/D-League/6653/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Ron-Baker/D-League/30538/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Tim-Hardaway-Jr/D-League/9386/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Ramon-Sessions/D-League/14/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Lance-Thomas/D-League/1948/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Dakari-Johnson/D-League/24676/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Khem-Birch/D-League/24151/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Justin-Anderson/D-League/24291/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Robert-Covington/D-League/11707/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Richaun-Holmes/D-League/42932/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Eric-Bledsoe/D-League/5714/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Derrick-Jones/D-League/59508/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Tyler-Ulis/D-League/52567/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/TJ-Warren/D-League/24292/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Alan-Williams/D-League/31153/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Kosta-Koufos/D-League/778/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Skal-Labissiere/D-League/42074/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Malachi-Richardson/D-League/49322/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Garrett-Temple/D-League/1757/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/George-Papagiannis/D-League/32198/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Brandon-Paul/D-League/2273/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Alfonzo-McKinnie/D-League/22478/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Lucas-Nogueira/D-League/24240/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/KJ-McDaniels/D-League/28823/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Carrick-Felix/D-League/23244/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Tim-Frazier/D-League/3977/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Mike-Scott/D-League/3753/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Kent-Bazemore/D-League/18858/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/DeAndre-Bembry/D-League/49891/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Ryan-Kelly/D-League/2193/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Mike-Muscala/D-League/17065/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Taurean-Prince/D-League/42410/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Dennis-Schroder/D-League/26503/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Avery-Bradley/D-League/2194/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Jae-Crowder/D-League/22407/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Gerald-Green/D-League/354/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Demetrius-Jackson/D-League/43395/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Jordan-Mickey/D-League/28236/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Terry-Rozier/D-League/24644/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Marcus-Smart/D-League/24275/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/James-Young/D-League/24681/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Isaiah-Canaan/D-League/12049/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Cristiano-Felicio/D-League/24840/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Jerian-Grant/D-League/9389/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Cameron-Payne/D-League/57476/Career/By_Season/Per_Game/Regular_Season", 
"https://basketball.realgm.com/player/Bobby-Portis/D-League/41433/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Denzel-Valentine/D-League/44077/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Paul-Zipser/D-League/26506/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Kay-Felder/D-League/57281/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Dahntay-Jones/D-League/445/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Edy-Tavares/D-League/39662/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Ian-Clark/D-League/14156/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Damian-Jones/D-League/42379/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Shaun-Livingston/D-League/377/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Kevon-Looney/D-League/41494/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/James-McAdoo/D-League/9304/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Patrick-McCaw/D-League/80940/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Patrick-Beverley/D-League/1684/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Clint-Capela/D-League/28284/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Sam-Dekker/D-League/28239/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Montrezl-Harrell/D-League/24290/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Chinanu-Onuaku/D-League/54847/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Isaiah-Taylor/D-League/56862/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Troy-Williams/D-League/24319/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Kyle-Wiltjer/D-League/24155/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Aaron-Brooks/D-League/53/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Rakeem-Christmas/D-League/24156/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Georges-Niang/D-League/42429/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Glenn-Robinson/D-League/28500/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Joe-Young/D-League/22869/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Alan-Anderson/D-League/939/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Brice-Johnson/D-League/24658/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Diamond-Stone/D-League/41493/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Wade-Baldwin-IV/D-League/81056/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Troy-Daniels/D-League/18948/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Deyonta-Davis/D-League/73162/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/JaMychal-Green/D-League/2187/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Andrew-Harrison/D-League/24306/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Jarell-Martin/D-League/41442/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Wayne-Selden/D-League/24687/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Khris-Middleton/D-League/4294/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Gary-Payton-II/D-League/80992/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Rashad-Vaughn/D-League/42082/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Josh-Huestis/D-League/23259/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Andre-Roberson/D-League/23283/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Allen-Crabbe/D-League/9300/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Ed-Davis/D-League/2174/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Festus-Ezeli/D-League/5962/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Jake-Layman/D-League/41248/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/CJ-McCollum/D-League/17251/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Shabazz-Napier/D-League/22395/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Tim-Quarterman/D-League/56701/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Noah-Vonleh/D-League/24323/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Kyle-Anderson/D-League/24265/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Joel-Anthony/D-League/789/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Davis-Bertans/D-League/24343/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Dewayne-Dedmon/D-League/28991/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Bryn-Forbes/D-League/42884/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Danny-Green/D-League/1642/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Patty-Mills/D-League/1632/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Dejounte-Murray/D-League/73136/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Jonathon-Simmons/D-League/30740/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Bruno-Caboclo/D-League/59172/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/DeMarre-Carroll/D-League/1631/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Cory-Joseph/D-League/7108/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Lucas-Nogueira/D-League/24240/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Patrick-Patterson/D-League/2152/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Jakob-Poeltl/D-League/53231/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Norman-Powell/D-League/24195/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Pascal-Siakam/D-League/81426/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Fred-VanVleet/D-League/44094/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Delon-Wright/D-League/56842/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Joel-Bolomboy/D-League/45041/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Alec-Burks/D-League/4169/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Rudy-Gobert/D-League/25858/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Shelvin-Mack/D-League/9419/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Raulzinho-Neto/D-League/24092/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Marcin-Gortat/D-League/145/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Brandon-Jennings/D-League/1609/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Ian-Mahinmi/D-League/264/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Sheldon-Mac/D-League/24189/Career/By_Season/Per_Game/Regular_Season",
"https://basketball.realgm.com/player/Chris-McCullough/D-League/41445/Career/By_Season/Per_Game/Regular_Season",
]
for x in list_of_urls:
	#url = "https://basketball.realgm.com/player/Chris-McCullough/D-League/41445/Career/By_Season/Per_Game/Regular_Season"
	response = requests.get(x)
	html = response.content
	soup = BeautifulSoup(html, "lxml")
	print ("Scraping Player")

	list_of_cells = []

	#parse the url
	splitList = x.split("/")
	playerName = splitList[4].split("-")
	print(playerName[0])
	print(playerName[1])

	fullName = playerName[0] + " " + playerName[1]
	list_of_cells.append(fullName)

	print(splitList)
	table = soup.findAll('tr', attrs={'class': 'per_game'})[1]
	for row in table.findAll('td'):
		list_of_cells.append(row.text)	
	writer.writerow(list_of_cells)



