-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathespnrankingscraper.py
60 lines (42 loc) · 1.39 KB
/
espnrankingscraper.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
import requests
from bs4 import BeautifulSoup
#gets the rankings from ESPN
#Works just need to connected to user interface
def espnscraper(base_url):
#request the url
r = requests.get(base_url)
#scrape the entire web page
soup = BeautifulSoup(r.content, 'html.parser')
data = []
table = soup.find('table', attrs={'class': "Table"})
print(table)
table_body = table.find('tbody')
print(table_body)
rows = table_body.find_all('tr')
dictionary1 = {}
for row in rows:
print(row)
#print(len(row))
cols = row.find_all('td')
#print(cols)
print(cols[0])
rankings = cols[0].text.strip()
#print()
#print(cols[1])
team_name = cols[1].find_all('a')[-1].text.strip()
dictionary1[rankings]= team_name
#print(team_name)
#print(cols)
#dictionary1[cols[1].text.strip()]
#cols = [ele.text.strip() for ele in cols]
#data.append([ele for ele in cols if ele])
# print(data)
# for i in range(len(data)):
# for k in range(len(data[i][1])):
# if data[i][1][k] == data[i][1][k].lower():
# data[i][1] = data[i][1][k-1] + data[i][1][k:]
# break
# print(data)
print(dictionary1)
#class= Table
#espnscraper('https://www.espn.com/mens-college-basketball/rankings/_/year/2018')