-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_playbyplay.py
More file actions
38 lines (28 loc) · 961 Bytes
/
get_playbyplay.py
File metadata and controls
38 lines (28 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests
from bs4 import BeautifulSoup
def CapturePlay(table):
Play = []
for index in range(1, len(table)):
details = table[index].findAll('td')
temp = []
for detail in details:
if detail.contents:
if isinstance(detail.contents[0], str):
temp.append(detail.contents[0])
else:
temp.append(detail.contents[0]['src'])
Play.append(temp)
return Play
def Quarter(soup, Q):
wrapper = soup.find('div', {'id': 'gp-quarter-' + Q})
table = wrapper.find('table').findAll('tr')
table = CapturePlay(table)
return table
def playbyplay(gameID, totalQuarter):
res = requests.get('http://www.espn.com/nba/playbyplay?gameId=' + gameID)
soup = BeautifulSoup(res.text, "lxml")
Play = []
for Q in range(1, totalQuarter + 1):
table = Quarter(soup, str(Q))
Play.append(table)
return Play