-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraping.py
53 lines (33 loc) · 1.09 KB
/
scraping.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
import numpy as np
import matplotlib.pyplot as plt
import requests
url = 'https://stats.nba.com/stats/playbyplayv2/?gameId=0021600732&startPeriod=0&endPeriod=14'
request_headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive',
'Host': 'stats.nba.com',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
r = requests.get(url, headers=request_headers)
y = r.json()
x = y['resultSets'][0]['rowSet']
scores = []
for row in y['resultSets'][0]['rowSet']:
scores.append(row[y['resultSets'][0]['headers'].index('SCOREMARGIN')])
print(scores)
newscores = []
for score in scores:
if score != None:
newscores.append(score)
print(newscores)
cleanleads = []
for lead in newscores:
lead = int(lead)
cleanleads.append(lead)
print(cleanleads)
plt.plot(cleanleads)
plt.show()