-
Notifications
You must be signed in to change notification settings - Fork 0
/
kenpomScraper.py
194 lines (136 loc) · 4.78 KB
/
kenpomScraper.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 24 19:59:08 2022
@author: roberthannon
"""
import requests
from bs4 import BeautifulSoup
URL = "https://kenpom.com/"
result = requests.get(URL)
soup = BeautifulSoup(result.content, 'html5lib')
#print(soup.prettify())
#print(soup.get_text())
#res = soup.title
#print(res.get_text())
#print(list(soup.children))
items = [type(item) for item in list(soup.children)]
#print(items)
html = list(soup.children)[1]
#print(list(html.children))
#print(type(item) for item in list(html.children))
#iterator = html.find_all('a')
iteratorNew = html.find_all('a')
iteratorWords = [x.get_text() for x in iteratorNew]
iteratorConf = html.find_all('td', class_='conf')
iteratorTeam = html.find_all('td', class_='next_left')
iteratorConference = [x.get_text() for x in iteratorConf]
iteratorTeams = [x.get_text() for x in iteratorTeam]
#print(iteratorTeams)
i = 0
teamsConf = {}
for x in iteratorTeams:
teamsConf[x] = [i + 1, iteratorConference[i]]
i = i + 1
#print(teamsConf)
val = input("What would you like to know? Press c for conference ranking, n for total ncaa rankings, h for head to head rankings, i for individual rankings, or b to see the best matchups of the day \n")
if val == "n":
i = 1
for x in iteratorTeams:
print (i, iteratorTeams[i-1], iteratorConference[i-1], "\n")
i = i + 1
if val == "c":
i = 0
p = 1
conf = input("What Conference? \n")
for x in iteratorConference:
if x == conf:
print(p, iteratorTeams[i])
p = p + 1
i = i + 1
if val == "h":
team1 = input("Team name? \n")
team2 = input("Another? \n")
if teamsConf[team1][0] < teamsConf[team2][0]:
print(team1)
else:
print(team2)
if val == "i":
team = input("Team name? \n")
print(teamsConf[team][0], team)
if val == "b":
URL2 = "https://www.ncaa.com/scoreboard/basketball-men/d1"
result2 = requests.get(URL2)
soup2 = BeautifulSoup(result2.content, 'html5lib')
iteratorNew2 = soup2.find_all('span', class_= 'gamePod-game-team-name')
iteratorWords2 = [x.get_text() for x in iteratorNew2]
games = []
i = 0
while i < len(iteratorWords2):
games.append([iteratorWords2[i], iteratorWords2[i + 1]])
i = i + 2
gamesRanking = []
for x in games:
if x[0] == "Southern U.":
x[0] = "Southern"
elif x[1] == "Southern U.":
x[1] = "Southern"
if x[0] == "Col. of Charleston":
x[0] = "Charleston"
elif x[1] == "Col. of Charleston":
x[1] = "Charleston"
if x[0] == "Central Conn. St.":
x[0] = "Central Connecticut"
elif x[1] == "Central Conn. St.":
x[1] = "Central Connecticut"
if x[0] == "N.C. Central":
x[0] = "North Carolina Central"
elif x[1] == "N.C. Central":
x[1] = "North Carolina Central"
if x[0] == "Bethune-Cookman":
x[0] = "Bethune Cookman"
elif x[1] == "Bethune-Cookman":
x[1] = "Bethune Cookman"
if x[0] == "Grambling":
x[0] = "Grambling St."
elif x[1] == "Grambling":
x[1] = "Grambling St."
if x[0] == "Prairie View":
x[0] = "Prairie View A&M"
elif x[1] == "Prairie View":
x[1] = "Prairie View A&M"
if x[0] == "UMES":
x[0] = "Maryland Eastern Shore"
elif x[1] == "UMES":
x[1] = "Maryland Eastern Shore"
if x[0] == "Alcorn":
x[0] = "Alcorn St."
elif x[1] == "Alcorn":
x[1] = "Alcorn St."
if x[0] == "UConn":
x[0] = "Connecticut"
elif x[1] == "UConn":
x[1] = "Connecticut"
if x[0] == "ETSU":
x[0] = "East Tennessee St."
elif x[1] == "ETSU":
x[1] = "East Tennessee St."
if x[0] == "St. John's (NY)":
x[0] = "St. John's"
elif x[1] == "St. John's (NY)":
x[1] = "St. John's"
if x[0] == "CSU Bakersfield":
x[0] = "Cal St. Bakersfield"
elif x[1] == "CSU Bakersfield":
x[1] = "Cal St. Bakersfield"
gamesRanking.append([x[0], x[1], abs(teamsConf[x[0]][0] - teamsConf[x[1]][0])])
for x in range(len(gamesRanking)-1, 0, -1):
for y in range(x):
if gamesRanking[y][2] > gamesRanking[y+1][2]:
temp = gamesRanking[y]
gamesRanking[y] = gamesRanking[y + 1]
gamesRanking[y+1] = temp
i=0
for x in gamesRanking:
i = i + 1
print(i, x[0], "at", x[1])